|
12 | 12 |
|
13 | 13 | @valid_params2 = { |
14 | 14 | path: @valid_path, |
15 | | - command: [RbConfig.ruby, '-e', 'puts "hello, world."; STDERR.puts "warning!"'], |
| 15 | + command: [RbConfig.ruby, '-e', 'puts "hello, #{STDIN.eof? ? "world" : STDIN.read.strip}."; STDERR.puts "warning!"'], |
| 16 | + stdin: "{{name}}", |
16 | 17 | expected_update_period_in_days: '1', |
17 | 18 | } |
18 | 19 |
|
|
27 | 28 | @event = Event.new |
28 | 29 | @event.agent = agents(:jane_weather_agent) |
29 | 30 | @event.payload = { |
30 | | - :cmd => "ls" |
| 31 | + 'name' => 'Huginn', |
| 32 | + 'cmd' => 'ls', |
31 | 33 | } |
32 | 34 | @event.save! |
33 | 35 |
|
|
58 | 60 |
|
59 | 61 | describe "#working?" do |
60 | 62 | it "generating events as scheduled" do |
61 | | - stub(@checker).run_command(@valid_path, 'pwd') { ["fake pwd output", "", 0] } |
| 63 | + stub(@checker).run_command(@valid_path, 'pwd', nil) { ["fake pwd output", "", 0] } |
62 | 64 |
|
63 | 65 | expect(@checker).not_to be_working |
64 | 66 | @checker.check |
|
71 | 73 |
|
72 | 74 | describe "#check" do |
73 | 75 | before do |
74 | | - stub(@checker).run_command(@valid_path, 'pwd') { ["fake pwd output", "", 0] } |
| 76 | + stub(@checker).run_command(@valid_path, 'pwd', nil) { ["fake pwd output", "", 0] } |
75 | 77 | end |
76 | 78 |
|
77 | 79 | it "should create an event when checking" do |
|
84 | 86 | it "should create an event when checking (unstubbed)" do |
85 | 87 | expect { @checker2.check }.to change { Event.count }.by(1) |
86 | 88 | expect(Event.last.payload[:path]).to eq(@valid_path) |
87 | | - expect(Event.last.payload[:command]).to eq([RbConfig.ruby, '-e', 'puts "hello, world."; STDERR.puts "warning!"']) |
| 89 | + expect(Event.last.payload[:command]).to eq([RbConfig.ruby, '-e', 'puts "hello, #{STDIN.eof? ? "world" : STDIN.read.strip}."; STDERR.puts "warning!"']) |
88 | 90 | expect(Event.last.payload[:output]).to eq('hello, world.') |
89 | 91 | expect(Event.last.payload[:errors]).to eq('warning!') |
90 | 92 | end |
|
97 | 99 |
|
98 | 100 | describe "#receive" do |
99 | 101 | before do |
100 | | - stub(@checker).run_command(@valid_path, @event.payload[:cmd]) { ["fake ls output", "", 0] } |
| 102 | + stub(@checker).run_command(@valid_path, @event.payload[:cmd], nil) { ["fake ls output", "", 0] } |
101 | 103 | end |
102 | 104 |
|
103 | 105 | it "creates events" do |
|
108 | 110 | expect(Event.last.payload[:output]).to eq("fake ls output") |
109 | 111 | end |
110 | 112 |
|
| 113 | + it "creates events (unstubbed)" do |
| 114 | + @checker2.receive([@event]) |
| 115 | + expect(Event.last.payload[:path]).to eq(@valid_path) |
| 116 | + expect(Event.last.payload[:output]).to eq('hello, Huginn.') |
| 117 | + expect(Event.last.payload[:errors]).to eq('warning!') |
| 118 | + end |
| 119 | + |
111 | 120 | it "does not run when should_run? is false" do |
112 | 121 | stub(Agents::ShellCommandAgent).should_run? { false } |
113 | 122 |
|
|
0 commit comments