@@ -2,10 +2,8 @@ require 'spec_helper' |
||
| 2 | 2 |
require 'mqtt' |
| 3 | 3 |
require './spec/support/fake_mqtt_server' |
| 4 | 4 |
|
| 5 |
-require 'pry' |
|
| 6 |
- |
|
| 7 | 5 |
describe Agents::MqttAgent do |
| 8 |
- before :each do |
|
| 6 |
+ before :each do |
|
| 9 | 7 |
# stub_request(:get, /parse/).to_return(:body => File.read(Rails.root.join("spec/data_fixtures/adioso_parse.json")), :status => 200, :headers => {"Content-Type" => "text/json"})
|
| 10 | 8 |
# stub_request(:get, /fares/).to_return(:body => File.read(Rails.root.join("spec/data_fixtures/adioso_fare.json")), :status => 200, :headers => {"Content-Type" => "text/json"})
|
| 11 | 9 |
@error_log = StringIO.new |
@@ -15,40 +13,40 @@ describe Agents::MqttAgent do |
||
| 15 | 13 |
@server.logger.level = Logger::DEBUG |
| 16 | 14 |
@server.start |
| 17 | 15 |
|
| 18 |
- @valid_params = {
|
|
| 16 |
+ @valid_params = {
|
|
| 19 | 17 |
'uri' => "mqtt://#{@server.address}:#{@server.port}",
|
| 20 | 18 |
'topic' => '/#', |
| 21 | 19 |
'max_read_time' => 1, |
| 22 | 20 |
'expected_update_period_in_days' => "2" |
| 23 | 21 |
} |
| 24 | 22 |
|
| 25 |
- @checker = Agents::MqttAgent.new( |
|
| 23 |
+ @checker = Agents::MqttAgent.new( |
|
| 26 | 24 |
:name => "somename", |
| 27 | 25 |
:options => @valid_params, |
| 28 | 26 |
:schedule => "midnight", |
| 29 | 27 |
) |
| 30 |
- @checker.user = users(:jane) |
|
| 31 |
- @checker.save! |
|
| 32 |
- end |
|
| 28 |
+ @checker.user = users(:jane) |
|
| 29 |
+ @checker.save! |
|
| 30 |
+ end |
|
| 33 | 31 |
|
| 34 | 32 |
after :each do |
| 35 | 33 |
@server.stop |
| 36 | 34 |
end |
| 37 | 35 |
|
| 38 |
- describe "#check" do |
|
| 39 |
- it "should check that initial run creates an event" do |
|
| 36 |
+ describe "#check" do |
|
| 37 |
+ it "should check that initial run creates an event" do |
|
| 40 | 38 |
expect { @checker.check }.to change { Event.count }.by(2)
|
| 41 |
- end |
|
| 42 |
- end |
|
| 39 |
+ end |
|
| 40 |
+ end |
|
| 43 | 41 |
|
| 44 |
- describe "#working?" do |
|
| 45 |
- it "checks if its generating events as scheduled" do |
|
| 46 |
- @checker.should_not be_working |
|
| 47 |
- @checker.check |
|
| 48 |
- @checker.reload.should be_working |
|
| 49 |
- three_days_from_now = 3.days.from_now |
|
| 50 |
- stub(Time).now { three_days_from_now }
|
|
| 51 |
- @checker.should_not be_working |
|
| 52 |
- end |
|
| 53 |
- end |
|
| 42 |
+ describe "#working?" do |
|
| 43 |
+ it "checks if its generating events as scheduled" do |
|
| 44 |
+ @checker.should_not be_working |
|
| 45 |
+ @checker.check |
|
| 46 |
+ @checker.reload.should be_working |
|
| 47 |
+ three_days_from_now = 3.days.from_now |
|
| 48 |
+ stub(Time).now { three_days_from_now }
|
|
| 49 |
+ @checker.should_not be_working |
|
| 50 |
+ end |
|
| 51 |
+ end |
|
| 54 | 52 |
end |