From dfa71d1f4560c978926b656d610ef70db9f64fce Mon Sep 17 00:00:00 2001 From: Andrew Cantino Date: Fri, 8 Aug 2014 19:59:19 -0700 Subject: [PATCH] upgrade RSpec --- Gemfile | 5 ++-- Gemfile.lock | 30 +++++++++++-------- spec/controllers/agents_controller_spec.rb | 2 +- spec/controllers/events_controller_spec.rb | 4 +-- spec/controllers/logs_controller_spec.rb | 2 +- spec/controllers/scenarios_controller_spec.rb | 4 +-- .../user_credentials_controller_spec.rb | 2 +- spec/helpers/dot_helper_spec.rb | 2 +- spec/lib/agents_exporter_spec.rb | 2 +- spec/models/agent_spec.rb | 2 +- spec/models/agents/growl_agent_spec.rb | 4 +-- spec/models/agents/human_task_agent_spec.rb | 14 ++++----- .../models/agents/weibo_publish_agent_spec.rb | 2 +- spec/models/scenario_import_spec.rb | 16 +++++----- spec/spec_helper.rb | 5 ++++ .../shared_examples/working_helpers.rb | 10 +++---- 16 files changed, 58 insertions(+), 48 deletions(-) diff --git a/Gemfile b/Gemfile index 242791af..acde98fd 100644 --- a/Gemfile +++ b/Gemfile @@ -88,8 +88,9 @@ group :development, :test do gem 'vcr' gem 'dotenv-rails' gem 'pry' - gem 'rspec-rails', '~> 2.14' - gem 'rspec', '~> 2.14' + gem 'rspec-rails', '~> 2.99' + gem 'rspec', '~> 2.99' + gem 'rspec-collection_matchers' gem 'shoulda-matchers' gem 'rr' gem 'delorean' diff --git a/Gemfile.lock b/Gemfile.lock index 68a42836..6cfc8531 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -238,22 +238,25 @@ GEM mime-types (>= 1.16) retriable (1.4.1) rr (1.1.2) - rspec (2.14.1) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - rspec-core (2.14.8) - rspec-expectations (2.14.5) + rspec (2.99.0) + rspec-core (~> 2.99.0) + rspec-expectations (~> 2.99.0) + rspec-mocks (~> 2.99.0) + rspec-collection_matchers (1.0.0) + rspec-expectations (>= 2.99.0.beta1) + rspec-core (2.99.1) + rspec-expectations (2.99.2) diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.6) - rspec-rails (2.14.2) + rspec-mocks (2.99.2) + rspec-rails (2.99.0) actionpack (>= 3.0) activemodel (>= 3.0) activesupport (>= 3.0) railties (>= 3.0) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) + rspec-collection_matchers + rspec-core (~> 2.99.0) + rspec-expectations (~> 2.99.0) + rspec-mocks (~> 2.99.0) rturk (2.12.1) erector nokogiri @@ -402,8 +405,9 @@ DEPENDENCIES rails (= 4.1.4) rails_12factor rr - rspec (~> 2.14) - rspec-rails (~> 2.14) + rspec (~> 2.99) + rspec-collection_matchers + rspec-rails (~> 2.99) rturk (~> 2.12.1) ruby-growl (~> 4.1.0) rufus-scheduler (~> 3.0.8) diff --git a/spec/controllers/agents_controller_spec.rb b/spec/controllers/agents_controller_spec.rb index 34ecac14..bb77629f 100644 --- a/spec/controllers/agents_controller_spec.rb +++ b/spec/controllers/agents_controller_spec.rb @@ -14,7 +14,7 @@ describe AgentsController do it "only returns Agents for the current user" do sign_in users(:bob) get :index - assigns(:agents).all? {|i| i.user.should == users(:bob) }.should be_true + assigns(:agents).all? {|i| i.user.should == users(:bob) }.should be_truthy end end diff --git a/spec/controllers/events_controller_spec.rb b/spec/controllers/events_controller_spec.rb index 8e9b97ca..94d0395c 100644 --- a/spec/controllers/events_controller_spec.rb +++ b/spec/controllers/events_controller_spec.rb @@ -10,14 +10,14 @@ describe EventsController do it "only returns Events created by Agents of the current user" do sign_in users(:bob) get :index - assigns(:events).all? {|i| i.user.should == users(:bob) }.should be_true + assigns(:events).all? {|i| i.user.should == users(:bob) }.should be_truthy end it "can filter by Agent" do sign_in users(:bob) get :index, :agent_id => agents(:bob_website_agent) assigns(:events).length.should == agents(:bob_website_agent).events.length - assigns(:events).all? {|i| i.agent.should == agents(:bob_website_agent) }.should be_true + assigns(:events).all? {|i| i.agent.should == agents(:bob_website_agent) }.should be_truthy lambda { get :index, :agent_id => agents(:jane_website_agent) diff --git a/spec/controllers/logs_controller_spec.rb b/spec/controllers/logs_controller_spec.rb index 117bd312..61e4cc7a 100644 --- a/spec/controllers/logs_controller_spec.rb +++ b/spec/controllers/logs_controller_spec.rb @@ -6,7 +6,7 @@ describe LogsController do sign_in users(:bob) get :index, :agent_id => agents(:bob_weather_agent).id assigns(:logs).length.should == agents(:bob_weather_agent).logs.length - assigns(:logs).all? {|i| i.agent.should == agents(:bob_weather_agent) }.should be_true + assigns(:logs).all? {|i| i.agent.should == agents(:bob_weather_agent) }.should be_truthy end it "only loads Agents owned by the current user" do diff --git a/spec/controllers/scenarios_controller_spec.rb b/spec/controllers/scenarios_controller_spec.rb index 9b122fee..1979cafe 100644 --- a/spec/controllers/scenarios_controller_spec.rb +++ b/spec/controllers/scenarios_controller_spec.rb @@ -12,7 +12,7 @@ describe ScenariosController do describe "GET index" do it "only returns Scenarios for the current user" do get :index - assigns(:scenarios).all? {|i| i.user.should == users(:bob) }.should be_true + assigns(:scenarios).all? {|i| i.user.should == users(:bob) }.should be_truthy end end @@ -50,7 +50,7 @@ describe ScenariosController do assigns(:exporter).options[:description].should == scenarios(:bob_weather).description assigns(:exporter).options[:agents].should == scenarios(:bob_weather).agents assigns(:exporter).options[:guid].should == scenarios(:bob_weather).guid - assigns(:exporter).options[:source_url].should be_false + assigns(:exporter).options[:source_url].should be_falsey response.headers['Content-Disposition'].should == 'attachment; filename="bob-s-weather-alert-scenario.json"' response.headers['Content-Type'].should == 'application/json; charset=utf-8' JSON.parse(response.body)["name"].should == scenarios(:bob_weather).name diff --git a/spec/controllers/user_credentials_controller_spec.rb b/spec/controllers/user_credentials_controller_spec.rb index b5b46ce3..48a33e3d 100644 --- a/spec/controllers/user_credentials_controller_spec.rb +++ b/spec/controllers/user_credentials_controller_spec.rb @@ -15,7 +15,7 @@ describe UserCredentialsController do describe "GET index" do it "only returns UserCredentials for the current user" do get :index - assigns(:user_credentials).all? {|i| i.user.should == users(:bob) }.should be_true + assigns(:user_credentials).all? {|i| i.user.should == users(:bob) }.should be_truthy end end diff --git a/spec/helpers/dot_helper_spec.rb b/spec/helpers/dot_helper_spec.rb index 60f63f2d..f0f33409 100644 --- a/spec/helpers/dot_helper_spec.rb +++ b/spec/helpers/dot_helper_spec.rb @@ -89,7 +89,7 @@ describe DotHelper do end end - describe DotHelper::DotDrawer do + describe "DotHelper::DotDrawer" do describe "#id" do it "properly escapes double quotaion and backslash" do DotHelper::DotDrawer.draw(foo: "") { diff --git a/spec/lib/agents_exporter_spec.rb b/spec/lib/agents_exporter_spec.rb index 974784fe..85ebd553 100644 --- a/spec/lib/agents_exporter_spec.rb +++ b/spec/lib/agents_exporter_spec.rb @@ -20,7 +20,7 @@ describe AgentsExporter do Time.parse(data[:exported_at]).should be_within(2).of(Time.now.utc) data[:links].should == [{ :source => 0, :receiver => 1 }] data[:agents].should == agent_list.map { |agent| exporter.agent_as_json(agent) } - data[:agents].all? { |agent_json| agent_json[:guid].present? && agent_json[:type].present? && agent_json[:name].present? }.should be_true + data[:agents].all? { |agent_json| agent_json[:guid].present? && agent_json[:type].present? && agent_json[:name].present? }.should be_truthy data[:agents][0].should_not have_key(:propagate_immediately) # can't receive events data[:agents][1].should_not have_key(:schedule) # can't be scheduled diff --git a/spec/models/agent_spec.rb b/spec/models/agent_spec.rb index 0eab7bd5..63aecf17 100644 --- a/spec/models/agent_spec.rb +++ b/spec/models/agent_spec.rb @@ -213,7 +213,7 @@ describe Agent do @checker.last_check_at.should be_nil Agents::SomethingSource.async_check(@checker.id) @checker.reload.last_check_at.should be_within(2).of(Time.now) - @checker.reload.options[:new].should be_true # Show that we save options + @checker.reload.options[:new].should be_truthy # Show that we save options end it "should log exceptions" do diff --git a/spec/models/agents/growl_agent_spec.rb b/spec/models/agents/growl_agent_spec.rb index 42ade239..09cfbcef 100644 --- a/spec/models/agents/growl_agent_spec.rb +++ b/spec/models/agents/growl_agent_spec.rb @@ -60,7 +60,7 @@ describe Agents::GrowlAgent do end @checker.register_growl - called.should be_true + called.should be_truthy end end @@ -78,7 +78,7 @@ describe Agents::GrowlAgent do mock(obj).notify(@checker.options[:growl_notification_name],subject,message) end @checker.notify_growl(subject,message) - called.should be_true + called.should be_truthy end end diff --git a/spec/models/agents/human_task_agent_spec.rb b/spec/models/agents/human_task_agent_spec.rb index 3bfb4825..865d153a 100644 --- a/spec/models/agents/human_task_agent_spec.rb +++ b/spec/models/agents/human_task_agent_spec.rb @@ -323,7 +323,7 @@ describe Agents::HumanTaskAgent do @checker.send :review_hits - assignments.all? {|a| a.approved == true }.should be_false + assignments.all? {|a| a.approved == true }.should be_falsey @checker.memory['hits'].should == { "JH3132836336DHG" => { 'event_id' => @event.id } } end @@ -341,7 +341,7 @@ describe Agents::HumanTaskAgent do @checker.send :review_hits - assignments.all? {|a| a.approved == true }.should be_false + assignments.all? {|a| a.approved == true }.should be_falsey @checker.memory['hits'].should == { "JH3132836336DHG" => { 'event_id' => @event.id } } end @@ -360,7 +360,7 @@ describe Agents::HumanTaskAgent do @checker.send :review_hits }.should change { Event.count }.by(1) - assignments.all? {|a| a.approved == true }.should be_true + assignments.all? {|a| a.approved == true }.should be_truthy hit.should be_disposed @checker.events.last.payload['answers'].should == [ @@ -405,7 +405,7 @@ describe Agents::HumanTaskAgent do @checker.send :review_hits }.should change { Event.count }.by(1) - assignments.all? {|a| a.approved == true }.should be_true + assignments.all? {|a| a.approved == true }.should be_truthy @checker.events.last.payload['answers'].should == [ { 'sentiment' => "sad", 'age_range' => "<50" }, @@ -458,7 +458,7 @@ describe Agents::HumanTaskAgent do @checker.send :review_hits }.should change { Event.count }.by(1) - assignments.all? {|a| a.approved == true }.should be_true + assignments.all? {|a| a.approved == true }.should be_truthy @checker.events.last.payload['answers'].should == [ { 'rating' => "1" }, @@ -520,7 +520,7 @@ describe Agents::HumanTaskAgent do # it approves the existing assignments - assignments.all? {|a| a.approved == true }.should be_true + assignments.all? {|a| a.approved == true }.should be_truthy hit.should be_disposed # it creates a new HIT for the poll @@ -582,7 +582,7 @@ describe Agents::HumanTaskAgent do # it approves the existing assignments - assignments.all? {|a| a.approved == true }.should be_true + assignments.all? {|a| a.approved == true }.should be_truthy hit.should be_disposed @checker.memory['hits'].should be_empty diff --git a/spec/models/agents/weibo_publish_agent_spec.rb b/spec/models/agents/weibo_publish_agent_spec.rb index 4a1317fc..bf69f311 100644 --- a/spec/models/agents/weibo_publish_agent_spec.rb +++ b/spec/models/agents/weibo_publish_agent_spec.rb @@ -53,7 +53,7 @@ describe Agents::WeiboPublishAgent do Agents::WeiboPublishAgent.async_receive(@checker.id, [event.id]) @sent_messages.count.should eq(1) @checker.events.count.should eq(1) - @sent_messages.first.include?("t.co").should_not be_true + @sent_messages.first.include?("t.co").should_not be_truthy end end diff --git a/spec/models/scenario_import_spec.rb b/spec/models/scenario_import_spec.rb index 836083f0..9b98b0a5 100644 --- a/spec/models/scenario_import_spec.rb +++ b/spec/models/scenario_import_spec.rb @@ -172,7 +172,7 @@ describe ScenarioImport do scenario_import.scenario.description.should == description scenario_import.scenario.guid.should == guid scenario_import.scenario.source_url.should == source_url - scenario_import.scenario.public.should be_false + scenario_import.scenario.public.should be_falsey end it "creates the Agents" do @@ -186,7 +186,7 @@ describe ScenarioImport do weather_agent.name.should == "a weather agent" weather_agent.schedule.should == "5pm" weather_agent.keep_events_for.should == 14 - weather_agent.propagate_immediately.should be_false + weather_agent.propagate_immediately.should be_falsey weather_agent.should be_disabled weather_agent.memory.should be_empty weather_agent.options.should == weather_agent_options @@ -195,7 +195,7 @@ describe ScenarioImport do trigger_agent.sources.should == [weather_agent] trigger_agent.schedule.should be_nil trigger_agent.keep_events_for.should == 0 - trigger_agent.propagate_immediately.should be_true + trigger_agent.propagate_immediately.should be_truthy trigger_agent.should_not be_disabled trigger_agent.memory.should be_empty trigger_agent.options.should == trigger_agent_options @@ -272,7 +272,7 @@ describe ScenarioImport do existing_scenario.description.should == description existing_scenario.name.should == name existing_scenario.source_url.should == source_url - existing_scenario.public.should be_false + existing_scenario.public.should be_falsey end it "updates any existing agents in the scenario, and makes new ones as needed" do @@ -290,7 +290,7 @@ describe ScenarioImport do weather_agent.name.should == "a weather agent" weather_agent.schedule.should == "5pm" weather_agent.keep_events_for.should == 14 - weather_agent.propagate_immediately.should be_false + weather_agent.propagate_immediately.should be_falsey weather_agent.should be_disabled weather_agent.memory.should be_empty weather_agent.options.should == weather_agent_options @@ -299,7 +299,7 @@ describe ScenarioImport do trigger_agent.sources.should == [weather_agent] trigger_agent.schedule.should be_nil trigger_agent.keep_events_for.should == 0 - trigger_agent.propagate_immediately.should be_true + trigger_agent.propagate_immediately.should be_truthy trigger_agent.should_not be_disabled trigger_agent.memory.should be_empty trigger_agent.options.should == trigger_agent_options @@ -318,7 +318,7 @@ describe ScenarioImport do scenario_import.should be_valid - scenario_import.import.should be_true + scenario_import.import.should be_truthy weather_agent = existing_scenario.agents.find_by(:guid => "a-weather-agent") weather_agent.name.should == "updated name" @@ -338,7 +338,7 @@ describe ScenarioImport do } } - scenario_import.import.should be_false + scenario_import.import.should be_falsey errors = scenario_import.errors.full_messages.to_sentence errors.should =~ /Name can't be blank/ diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5be67d89..8b4c71b6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -32,6 +32,11 @@ RSpec.configure do |config| # instead of true. config.use_transactional_fixtures = true + # rspec-rails 3 will no longer automatically infer an example group's spec type + # from the file location. You can explicitly opt-in to this feature using this + # snippet: + config.infer_spec_type_from_file_location! + # If true, the base class of anonymous controllers will be inferred # automatically. This will be the default behavior in future versions of # rspec-rails. diff --git a/spec/support/shared_examples/working_helpers.rb b/spec/support/shared_examples/working_helpers.rb index 6da44a6e..da0d7c2c 100644 --- a/spec/support/shared_examples/working_helpers.rb +++ b/spec/support/shared_examples/working_helpers.rb @@ -7,23 +7,23 @@ shared_examples_for WorkingHelpers do agent.last_error_log_at = 10.minutes.ago agent.last_event_at = 10.minutes.ago - agent.recent_error_logs?.should be_true + agent.recent_error_logs?.should be_truthy agent.last_error_log_at = 11.minutes.ago agent.last_event_at = 10.minutes.ago - agent.recent_error_logs?.should be_true + agent.recent_error_logs?.should be_truthy agent.last_error_log_at = 5.minutes.ago agent.last_event_at = 10.minutes.ago - agent.recent_error_logs?.should be_true + agent.recent_error_logs?.should be_truthy agent.last_error_log_at = 15.minutes.ago agent.last_event_at = 10.minutes.ago - agent.recent_error_logs?.should be_false + agent.recent_error_logs?.should be_falsey agent.last_error_log_at = 2.days.ago agent.last_event_at = 10.minutes.ago - agent.recent_error_logs?.should be_false + agent.recent_error_logs?.should be_falsey end end