<commit_before>require 'spec_helper'
require 'mqtt'
require './spec/support/fake_mqtt_server'

require 'pry'

describe Agents::MqttAgent do
	before :each do
    # 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"})
    # 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"})
    @error_log = StringIO.new
    @server = MQTT::FakeServer.new(1234, '127.0.0.1')
    @server.just_one = true
    @server.logger = Logger.new(@error_log)
    @server.logger.level = Logger::DEBUG
    @server.start

		@valid_params = {
      'uri' => "mqtt://#{@server.address}:#{@server.port}",
      'topic' => '/#',
      'max_read_time' => 1,
      'expected_update_period_in_days' => "2"
    }

		@checker = Agents::MqttAgent.new(
      :name => "somename", 
      :options => @valid_params, 
      :schedule => "midnight",
    )
		@checker.user = users(:jane)
		@checker.save!
	end

  after :each do
    @server.stop
  end

	describe "#check" do
		it "should check that initial run creates an event" do
      expect { @checker.check }.to change { Event.count }.by(2)
		end
	end

	describe "#working?" do
		it "checks if its generating events as scheduled" do
			@checker.should_not be_working
			@checker.check
			@checker.reload.should be_working
			three_days_from_now = 3.days.from_now
			stub(Time).now { three_days_from_now }
			@checker.should_not be_working
		end
	end
end<commit_msg>Mixed whitespace :(<commit_after>require 'spec_helper'
require 'mqtt'
require './spec/support/fake_mqtt_server'

describe Agents::MqttAgent do
  before :each do
    # 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"})
    # 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"})
    @error_log = StringIO.new
    @server = MQTT::FakeServer.new(1234, '127.0.0.1')
    @server.just_one = true
    @server.logger = Logger.new(@error_log)
    @server.logger.level = Logger::DEBUG
    @server.start

    @valid_params = {
      'uri' => "mqtt://#{@server.address}:#{@server.port}",
      'topic' => '/#',
      'max_read_time' => 1,
      'expected_update_period_in_days' => "2"
    }

    @checker = Agents::MqttAgent.new(
      :name => "somename", 
      :options => @valid_params, 
      :schedule => "midnight",
    )
    @checker.user = users(:jane)
    @checker.save!
  end

  after :each do
    @server.stop
  end

  describe "#check" do
    it "should check that initial run creates an event" do
      expect { @checker.check }.to change { Event.count }.by(2)
    end
  end

  describe "#working?" do
    it "checks if its generating events as scheduled" do
      @checker.should_not be_working
      @checker.check
      @checker.reload.should be_working
      three_days_from_now = 3.days.from_now
      stub(Time).now { three_days_from_now }
      @checker.should_not be_working
    end
  end
end
{'fraction_non_alphanumeric': 0.15794306703397612, 'fraction_numerical': 0.012243648607284972, 'mean_word_length': 3.404312668463612, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5815502', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1161, 'n_words': 227}