From 0677052ae4f37b50411b862111cc716fd0c3d347 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Wed, 9 May 2012 07:58:06 -0500 Subject: [PATCH 01/42] dev: refactor a spec --- spec/rspec/rails/matchers/redirect_to_spec.rb | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/spec/rspec/rails/matchers/redirect_to_spec.rb b/spec/rspec/rails/matchers/redirect_to_spec.rb index b35d10adfd..a2fc2c646c 100644 --- a/spec/rspec/rails/matchers/redirect_to_spec.rb +++ b/spec/rspec/rails/matchers/redirect_to_spec.rb @@ -6,15 +6,11 @@ let(:response) { ActionController::TestResponse.new } - it "delegates to assert_redirected_to" do - self.should_receive(:assert_redirected_to).with("destination") - "response".should redirect_to("destination") - end - context "with should" do context "when assert_redirected_to passes" do + def assert_redirected_to(*); end + it "passes" do - self.stub!(:assert_redirected_to) expect do response.should redirect_to("destination") end.to_not raise_exception @@ -22,21 +18,23 @@ end context "when assert_redirected_to fails" do + def assert_redirected_to(*) + raise ActiveSupport::TestCase::Assertion.new("this message") + end + it "uses failure message from assert_redirected_to" do - self.stub!(:assert_redirected_to) do - raise ActiveSupport::TestCase::Assertion.new("this message") - end expect do response.should redirect_to("destination") - end.to raise_error("this message") + end.to raise_exception("this message") end end context "when fails due to some other exception" do + def assert_redirected_to(*) + raise "oops" + end + it "raises that exception" do - self.stub!(:assert_redirected_to) do - raise "oops" - end expect do response.should redirect_to("destination") end.to raise_exception("oops") @@ -46,10 +44,11 @@ context "with should_not" do context "when assert_redirected_to fails" do + def assert_redirected_to(*) + raise ActiveSupport::TestCase::Assertion.new("this message") + end + it "passes" do - self.stub!(:assert_redirected_to) do - raise ActiveSupport::TestCase::Assertion.new("this message") - end expect do response.should_not redirect_to("destination") end.to_not raise_exception @@ -57,19 +56,21 @@ end context "when assert_redirected_to passes" do + def assert_redirected_to(*); end + it "fails with custom failure message" do - self.stub!(:assert_redirected_to) expect do response.should_not redirect_to("destination") - end.to raise_error(/expected not to redirect to \"destination\", but did/) + end.to raise_exception(/expected not to redirect to \"destination\", but did/) end end context "when fails due to some other exception" do + def assert_redirected_to(*) + raise "oops" + end + it "raises that exception" do - self.stub!(:assert_redirected_to) do - raise "oops" - end expect do response.should_not redirect_to("destination") end.to raise_exception("oops") From 83e24bca5d3ca86360a70f76fbe1e592f0ab5e63 Mon Sep 17 00:00:00 2001 From: Dan Rasband Date: Thu, 10 May 2012 15:09:30 -0600 Subject: [PATCH 02/42] Added configuration to allow for custom application engine. --- lib/rspec/rails.rb | 1 + lib/rspec/rails/engine_support.rb | 9 +++++++ .../rails/example/controller_example_group.rb | 2 +- .../rails/example/mailer_example_group.rb | 2 +- .../rails/example/request_example_group.rb | 4 +-- .../rails/example/routing_example_group.rb | 2 +- spec/rspec/rails/configuration_spec.rb | 13 ++++++++++ .../example/controller_example_group_spec.rb | 23 +++++++++++++++++ .../example/mailer_example_group_spec.rb | 20 +++++++++++++++ .../example/request_example_group_spec.rb | 21 ++++++++++++++++ .../example/routing_example_group_spec.rb | 25 +++++++++++++++++++ spec/support/engine_example.rb | 12 +++++++++ 12 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 lib/rspec/rails/engine_support.rb create mode 100644 spec/support/engine_example.rb diff --git a/lib/rspec/rails.rb b/lib/rspec/rails.rb index 53047ed6a1..f226022fd6 100644 --- a/lib/rspec/rails.rb +++ b/lib/rspec/rails.rb @@ -9,6 +9,7 @@ require 'rspec/rails/view_rendering' require 'rspec/rails/adapters' require 'rspec/rails/matchers' +require 'rspec/rails/engine_support' require 'rspec/rails/fixture_support' require 'rspec/rails/mocks' require 'rspec/rails/module_inclusion' diff --git a/lib/rspec/rails/engine_support.rb b/lib/rspec/rails/engine_support.rb new file mode 100644 index 0000000000..01e280feee --- /dev/null +++ b/lib/rspec/rails/engine_support.rb @@ -0,0 +1,9 @@ +module RSpec + module Rails + module EngineSupport + RSpec::configure do |config| + config.add_setting :application, :default => ::Rails.application + end + end + end +end diff --git a/lib/rspec/rails/example/controller_example_group.rb b/lib/rspec/rails/example/controller_example_group.rb index eaaa028b55..92e76d5bca 100644 --- a/lib/rspec/rails/example/controller_example_group.rb +++ b/lib/rspec/rails/example/controller_example_group.rb @@ -120,7 +120,7 @@ def method_missing(method, *args, &block) metadata[:type] = :controller before do - @routes = ::Rails.application.routes + @routes = RSpec.configuration.application.routes ActionController::Base.allow_forgery_protection = false end end diff --git a/lib/rspec/rails/example/mailer_example_group.rb b/lib/rspec/rails/example/mailer_example_group.rb index 03245c56bc..4ebb8bb959 100644 --- a/lib/rspec/rails/example/mailer_example_group.rb +++ b/lib/rspec/rails/example/mailer_example_group.rb @@ -7,7 +7,7 @@ module MailerExampleGroup included do metadata[:type] = :mailer - include ::Rails.application.routes.url_helpers + include RSpec.configuration.application.routes.url_helpers options = ::Rails.configuration.action_mailer.default_url_options options.each { |key, value| default_url_options[key] = value } if options end diff --git a/lib/rspec/rails/example/request_example_group.rb b/lib/rspec/rails/example/request_example_group.rb index 80b9a57466..602701d14b 100644 --- a/lib/rspec/rails/example/request_example_group.rb +++ b/lib/rspec/rails/example/request_example_group.rb @@ -9,14 +9,14 @@ module RequestExampleGroup include ActionController::TemplateAssertions def app - ::Rails.application + RSpec.configuration.application end included do metadata[:type] = :request before do - @routes = ::Rails.application.routes + @routes = RSpec.configuration.application.routes end end end diff --git a/lib/rspec/rails/example/routing_example_group.rb b/lib/rspec/rails/example/routing_example_group.rb index 066b29709e..0e11ac6216 100644 --- a/lib/rspec/rails/example/routing_example_group.rb +++ b/lib/rspec/rails/example/routing_example_group.rb @@ -12,7 +12,7 @@ module RoutingExampleGroup metadata[:type] = :routing before do - @routes = ::Rails.application.routes + @routes = RSpec.configuration.application.routes end end diff --git a/spec/rspec/rails/configuration_spec.rb b/spec/rspec/rails/configuration_spec.rb index 258bef1b52..ee8febc841 100644 --- a/spec/rspec/rails/configuration_spec.rb +++ b/spec/rspec/rails/configuration_spec.rb @@ -3,10 +3,12 @@ describe "configuration" do before do @orig_render_views = RSpec.configuration.render_views? + @orig_application = RSpec.configuration.application end after do RSpec.configuration.render_views = @orig_render_views + RSpec.configuration.application = @orig_application end describe "#render_views?" do @@ -23,4 +25,15 @@ RSpec.configuration.render_views?.should be_true end end + + describe "#application" do + it "is Rails.application by default" do + RSpec.configuration.application.should eq(::Rails.application) + end + + it "allows for custom application" do + RSpec.configuration.application = RSpec::EngineExample + RSpec.configuration.application.should eq(RSpec::EngineExample) + end + end end diff --git a/spec/rspec/rails/example/controller_example_group_spec.rb b/spec/rspec/rails/example/controller_example_group_spec.rb index f5e390edd1..58f535585b 100644 --- a/spec/rspec/rails/example/controller_example_group_spec.rb +++ b/spec/rspec/rails/example/controller_example_group_spec.rb @@ -96,5 +96,28 @@ module RSpec::Rails controller_class.superclass.should eq(ApplicationController) end end + + describe "#application" do + before do + @orig_application = RSpec.configuration.application + RSpec.configuration.application = RSpec::EngineExample + end + + after do + RSpec.configuration.application = @orig_application + end + + it "still delegates name routes to underlying controller" do + controller = double('controller') + controller.stub(:bars_path).and_return('/foos') + + example = group.new + example.stub(:controller => controller) + + example.instance_variable_set(:@orig_routes, RSpec.configuration.application.routes) + + example.bars_path.should eq('/foos') + end + end end end diff --git a/spec/rspec/rails/example/mailer_example_group_spec.rb b/spec/rspec/rails/example/mailer_example_group_spec.rb index c01c4fe540..52a8953253 100644 --- a/spec/rspec/rails/example/mailer_example_group_spec.rb +++ b/spec/rspec/rails/example/mailer_example_group_spec.rb @@ -17,5 +17,25 @@ module ::Rails; end end group.metadata[:type].should eq(:mailer) end + + describe "custom application" do + before do + @orig_application = RSpec.configuration.application + RSpec.configuration.application = RSpec::EngineExample + end + + after do + RSpec.configuration.application = @orig_application + end + + it "should include custom application's url helpers" do + group = RSpec::Core::ExampleGroup.describe do + include MailerExampleGroup + end + + example = group.new + example.bars_path.should == '/bars' + end + end end end diff --git a/spec/rspec/rails/example/request_example_group_spec.rb b/spec/rspec/rails/example/request_example_group_spec.rb index fdd8918cec..d013dfc36e 100644 --- a/spec/rspec/rails/example/request_example_group_spec.rb +++ b/spec/rspec/rails/example/request_example_group_spec.rb @@ -13,5 +13,26 @@ module RSpec::Rails end group.metadata[:type].should eq(:request) end + + describe "#app" do + before do + @orig_application = RSpec.configuration.application + RSpec.configuration.application = RSpec::EngineExample + end + + after do + RSpec.configuration.application = @orig_application + end + + it "sets app as custom application" do + group = RSpec::Core::ExampleGroup.describe do + include RequestExampleGroup + end + + example = group.new + + example.app.should eq(RSpec::EngineExample) + end + end end end diff --git a/spec/rspec/rails/example/routing_example_group_spec.rb b/spec/rspec/rails/example/routing_example_group_spec.rb index 4c3ed0c543..b2df2cef71 100644 --- a/spec/rspec/rails/example/routing_example_group_spec.rb +++ b/spec/rspec/rails/example/routing_example_group_spec.rb @@ -28,5 +28,30 @@ module RSpec::Rails example.foo_path.should == "foo" end end + + describe "custom application routes" do + before do + @orig_application = RSpec.configuration.application + RSpec.configuration.application = RSpec::EngineExample + end + + after do + RSpec.configuration.application = @orig_application + end + + it "provides routes of custom application" do + group = RSpec::Core::ExampleGroup.describe do + include RoutingExampleGroup + end + + example = group.new + + # Because this relies on before hooks, I have to stub this in. + example.stub(:routes => RSpec.configuration.application.routes) + + example.bars_path.should == "/bars" + end + + end end end diff --git a/spec/support/engine_example.rb b/spec/support/engine_example.rb new file mode 100644 index 0000000000..aad41e650b --- /dev/null +++ b/spec/support/engine_example.rb @@ -0,0 +1,12 @@ +module RSpec + class EngineExample < ::Rails::Engine + def self.activate + end + end +end + + +RSpec::EngineExample.routes.draw do + root :to => "foo#index" + resources :bars +end From acd46c25348cf1cc71747aa04b192b9419adedc7 Mon Sep 17 00:00:00 2001 From: Dan Rasband Date: Wed, 16 May 2012 13:39:20 -0600 Subject: [PATCH 03/42] Make code version specific for rails 3.1 and up This commit adds Rails version checking to the RSpec application configuration to handle Rails 3.0.x. The Rails::Engine class, while available in Rails 3.0, does not have the capability to draw routes as it does in 3.1 and above. --- lib/rspec/rails.rb | 2 +- lib/rspec/rails/engine_support.rb | 12 +++--- .../rails/example/controller_example_group.rb | 6 ++- .../rails/example/mailer_example_group.rb | 6 ++- .../rails/example/request_example_group.rb | 12 +++++- .../rails/example/routing_example_group.rb | 6 ++- spec/rspec/rails/configuration_spec.rb | 40 +++++++++++++++---- .../example/controller_example_group_spec.rb | 20 +++++++--- .../example/mailer_example_group_spec.rb | 16 ++++++-- .../example/request_example_group_spec.rb | 16 ++++++-- .../example/routing_example_group_spec.rb | 22 ++++++---- spec/spec_helper.rb | 7 ++++ spec/support/engine_example.rb | 6 --- 13 files changed, 126 insertions(+), 45 deletions(-) diff --git a/lib/rspec/rails.rb b/lib/rspec/rails.rb index f226022fd6..fc4e3dc10a 100644 --- a/lib/rspec/rails.rb +++ b/lib/rspec/rails.rb @@ -9,10 +9,10 @@ require 'rspec/rails/view_rendering' require 'rspec/rails/adapters' require 'rspec/rails/matchers' -require 'rspec/rails/engine_support' require 'rspec/rails/fixture_support' require 'rspec/rails/mocks' require 'rspec/rails/module_inclusion' require 'rspec/rails/example' require 'rspec/rails/vendor/capybara' require 'rspec/rails/vendor/webrat' +require 'rspec/rails/engine_support' diff --git a/lib/rspec/rails/engine_support.rb b/lib/rspec/rails/engine_support.rb index 01e280feee..636d91c5e6 100644 --- a/lib/rspec/rails/engine_support.rb +++ b/lib/rspec/rails/engine_support.rb @@ -1,8 +1,10 @@ -module RSpec - module Rails - module EngineSupport - RSpec::configure do |config| - config.add_setting :application, :default => ::Rails.application +if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + module RSpec + module Rails + module EngineSupport + RSpec::configure do |config| + config.add_setting :application, :default => ::Rails.application + end end end end diff --git a/lib/rspec/rails/example/controller_example_group.rb b/lib/rspec/rails/example/controller_example_group.rb index 92e76d5bca..8ca9824457 100644 --- a/lib/rspec/rails/example/controller_example_group.rb +++ b/lib/rspec/rails/example/controller_example_group.rb @@ -120,7 +120,11 @@ def method_missing(method, *args, &block) metadata[:type] = :controller before do - @routes = RSpec.configuration.application.routes + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + @routes = RSpec.configuration.application.routes + else + @routes = ::Rails.application.routes + end ActionController::Base.allow_forgery_protection = false end end diff --git a/lib/rspec/rails/example/mailer_example_group.rb b/lib/rspec/rails/example/mailer_example_group.rb index 4ebb8bb959..257058d82f 100644 --- a/lib/rspec/rails/example/mailer_example_group.rb +++ b/lib/rspec/rails/example/mailer_example_group.rb @@ -7,7 +7,11 @@ module MailerExampleGroup included do metadata[:type] = :mailer - include RSpec.configuration.application.routes.url_helpers + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + include RSpec.configuration.application.routes.url_helpers + else + include ::Rails.application.routes.url_helpers + end options = ::Rails.configuration.action_mailer.default_url_options options.each { |key, value| default_url_options[key] = value } if options end diff --git a/lib/rspec/rails/example/request_example_group.rb b/lib/rspec/rails/example/request_example_group.rb index 602701d14b..1db2a94bf2 100644 --- a/lib/rspec/rails/example/request_example_group.rb +++ b/lib/rspec/rails/example/request_example_group.rb @@ -9,14 +9,22 @@ module RequestExampleGroup include ActionController::TemplateAssertions def app - RSpec.configuration.application + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + return RSpec.configuration.application + else + return ::Rails.application + end end included do metadata[:type] = :request before do - @routes = RSpec.configuration.application.routes + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + @routes = RSpec.configuration.application.routes + else + @routes = ::Rails.application.routes + end end end end diff --git a/lib/rspec/rails/example/routing_example_group.rb b/lib/rspec/rails/example/routing_example_group.rb index 0e11ac6216..bb07c5fb14 100644 --- a/lib/rspec/rails/example/routing_example_group.rb +++ b/lib/rspec/rails/example/routing_example_group.rb @@ -12,7 +12,11 @@ module RoutingExampleGroup metadata[:type] = :routing before do - @routes = RSpec.configuration.application.routes + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + @routes = RSpec.configuration.application.routes + else + @routes = ::Rails.application.routes + end end end diff --git a/spec/rspec/rails/configuration_spec.rb b/spec/rspec/rails/configuration_spec.rb index ee8febc841..323cd140e8 100644 --- a/spec/rspec/rails/configuration_spec.rb +++ b/spec/rspec/rails/configuration_spec.rb @@ -3,12 +3,10 @@ describe "configuration" do before do @orig_render_views = RSpec.configuration.render_views? - @orig_application = RSpec.configuration.application end after do RSpec.configuration.render_views = @orig_render_views - RSpec.configuration.application = @orig_application end describe "#render_views?" do @@ -27,13 +25,41 @@ end describe "#application" do - it "is Rails.application by default" do - RSpec.configuration.application.should eq(::Rails.application) + + context "default" do + + it "is Rails.application by default" do + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + RSpec.configuration.application.should eq(::Rails.application) + else + expect { RSpec.configuration.application }.should raise_error + end + end + end - it "allows for custom application" do - RSpec.configuration.application = RSpec::EngineExample - RSpec.configuration.application.should eq(RSpec::EngineExample) + context "custom rack application" do + before do + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + @orig_application = RSpec.configuration.application + end + end + + after do + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + RSpec.configuration.application = @orig_application + end + end + + it "allows for custom application" do + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + RSpec.configuration.application = RSpec::EngineExample + RSpec.configuration.application.should eq(RSpec::EngineExample) + else + expect { RSpec.configuration.application = RSpec::EngineExample }.should raise_error + end + end + end end end diff --git a/spec/rspec/rails/example/controller_example_group_spec.rb b/spec/rspec/rails/example/controller_example_group_spec.rb index 58f535585b..95a47d0146 100644 --- a/spec/rspec/rails/example/controller_example_group_spec.rb +++ b/spec/rspec/rails/example/controller_example_group_spec.rb @@ -99,12 +99,16 @@ module RSpec::Rails describe "#application" do before do - @orig_application = RSpec.configuration.application - RSpec.configuration.application = RSpec::EngineExample + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + @orig_application = RSpec.configuration.application + RSpec.configuration.application = RSpec::EngineExample + end end after do - RSpec.configuration.application = @orig_application + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + RSpec.configuration.application = @orig_application + end end it "still delegates name routes to underlying controller" do @@ -114,9 +118,13 @@ module RSpec::Rails example = group.new example.stub(:controller => controller) - example.instance_variable_set(:@orig_routes, RSpec.configuration.application.routes) - - example.bars_path.should eq('/foos') + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + example.instance_variable_set(:@orig_routes, RSpec.configuration.application.routes) + example.bars_path.should eq('/foos') + else + example.instance_variable_set(:@orig_routes, ::Rails.application.routes) + expect { example.bars_path }.should raise_error + end end end end diff --git a/spec/rspec/rails/example/mailer_example_group_spec.rb b/spec/rspec/rails/example/mailer_example_group_spec.rb index 52a8953253..61706a55e1 100644 --- a/spec/rspec/rails/example/mailer_example_group_spec.rb +++ b/spec/rspec/rails/example/mailer_example_group_spec.rb @@ -20,12 +20,16 @@ module ::Rails; end describe "custom application" do before do - @orig_application = RSpec.configuration.application - RSpec.configuration.application = RSpec::EngineExample + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + @orig_application = RSpec.configuration.application + RSpec.configuration.application = RSpec::EngineExample + end end after do - RSpec.configuration.application = @orig_application + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + RSpec.configuration.application = @orig_application + end end it "should include custom application's url helpers" do @@ -34,7 +38,11 @@ module ::Rails; end end example = group.new - example.bars_path.should == '/bars' + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + example.bars_path.should == '/bars' + else + expect { example.bars_path }.should raise_error + end end end end diff --git a/spec/rspec/rails/example/request_example_group_spec.rb b/spec/rspec/rails/example/request_example_group_spec.rb index d013dfc36e..2e127adb51 100644 --- a/spec/rspec/rails/example/request_example_group_spec.rb +++ b/spec/rspec/rails/example/request_example_group_spec.rb @@ -16,12 +16,16 @@ module RSpec::Rails describe "#app" do before do - @orig_application = RSpec.configuration.application - RSpec.configuration.application = RSpec::EngineExample + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + @orig_application = RSpec.configuration.application + RSpec.configuration.application = RSpec::EngineExample + end end after do - RSpec.configuration.application = @orig_application + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + RSpec.configuration.application = @orig_application + end end it "sets app as custom application" do @@ -31,7 +35,11 @@ module RSpec::Rails example = group.new - example.app.should eq(RSpec::EngineExample) + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + example.app.should eq(RSpec::EngineExample) + else + example.app.should eq(::Rails.application) + end end end end diff --git a/spec/rspec/rails/example/routing_example_group_spec.rb b/spec/rspec/rails/example/routing_example_group_spec.rb index b2df2cef71..b41fe2c456 100644 --- a/spec/rspec/rails/example/routing_example_group_spec.rb +++ b/spec/rspec/rails/example/routing_example_group_spec.rb @@ -31,12 +31,16 @@ module RSpec::Rails describe "custom application routes" do before do - @orig_application = RSpec.configuration.application - RSpec.configuration.application = RSpec::EngineExample + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + @orig_application = RSpec.configuration.application + RSpec.configuration.application = RSpec::EngineExample + end end after do - RSpec.configuration.application = @orig_application + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + RSpec.configuration.application = @orig_application + end end it "provides routes of custom application" do @@ -46,10 +50,14 @@ module RSpec::Rails example = group.new - # Because this relies on before hooks, I have to stub this in. - example.stub(:routes => RSpec.configuration.application.routes) - - example.bars_path.should == "/bars" + if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + # Because this relies on before hooks, I have to stub this in. + example.stub(:routes => RSpec.configuration.application.routes) + example.bars_path.should == "/bars" + else + example.stub(:routes => ::Rails.application.routes) + expect { example.bars_path }.should raise_error + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 13373f1a65..e600660c26 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,6 +16,13 @@ def self.run_all(reporter=nil) end end +if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') + RSpec::EngineExample.routes.draw do + root :to => "foo#index" + resources :bars + end +end + RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.filter_run :focus diff --git a/spec/support/engine_example.rb b/spec/support/engine_example.rb index aad41e650b..882f747208 100644 --- a/spec/support/engine_example.rb +++ b/spec/support/engine_example.rb @@ -4,9 +4,3 @@ def self.activate end end end - - -RSpec::EngineExample.routes.draw do - root :to => "foo#index" - resources :bars -end From 1cd9a3c927934bcf7637ba7f4877484c84174598 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Mon, 21 May 2012 23:00:48 -0500 Subject: [PATCH 04/42] refactor matchers to conform to internal changes in rspec-expectations --- lib/rspec/rails/matchers/be_a_new.rb | 6 ++++- lib/rspec/rails/matchers/redirect_to.rb | 8 +++--- lib/rspec/rails/matchers/render_template.rb | 2 +- lib/rspec/rails/matchers/routing_matchers.rb | 27 +++++++++++--------- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/rspec/rails/matchers/be_a_new.rb b/lib/rspec/rails/matchers/be_a_new.rb index f08689c419..33837f4be9 100644 --- a/lib/rspec/rails/matchers/be_a_new.rb +++ b/lib/rspec/rails/matchers/be_a_new.rb @@ -2,9 +2,13 @@ module RSpec::Rails::Matchers class BeANew include RSpec::Matchers::BuiltIn::BaseMatcher + def initialize(expected) + @expected = expected + end + # @api private def matches?(actual) - super + @actual = actual actual.is_a?(expected) && actual.new_record? && attributes_match?(actual) end diff --git a/lib/rspec/rails/matchers/redirect_to.rb b/lib/rspec/rails/matchers/redirect_to.rb index 8412bf094c..e488924a85 100644 --- a/lib/rspec/rails/matchers/redirect_to.rb +++ b/lib/rspec/rails/matchers/redirect_to.rb @@ -4,14 +4,14 @@ class RedirectTo include RSpec::Matchers::BuiltIn::BaseMatcher def initialize(scope, expected) - super(expected) + @expected = expected @scope = scope end # @api private - def matches?(actual) + def matches?(_) match_unless_raises ActiveSupport::TestCase::Assertion do - @scope.assert_redirected_to(expected) + @scope.assert_redirected_to(@expected) end end @@ -22,7 +22,7 @@ def failure_message_for_should # @api private def failure_message_for_should_not - "expected not to redirect to #{expected.inspect}, but did" + "expected not to redirect to #{@expected.inspect}, but did" end end diff --git a/lib/rspec/rails/matchers/render_template.rb b/lib/rspec/rails/matchers/render_template.rb index f12c900673..87abef1457 100644 --- a/lib/rspec/rails/matchers/render_template.rb +++ b/lib/rspec/rails/matchers/render_template.rb @@ -4,7 +4,7 @@ class RenderTemplateMatcher include RSpec::Matchers::BuiltIn::BaseMatcher def initialize(scope, expected, message=nil) - super(Symbol === expected ? expected.to_s : expected) + @expected = Symbol === expected ? expected.to_s : expected @message = message @scope = scope end diff --git a/lib/rspec/rails/matchers/routing_matchers.rb b/lib/rspec/rails/matchers/routing_matchers.rb index 987b05acce..7d4f1fcbbf 100644 --- a/lib/rspec/rails/matchers/routing_matchers.rb +++ b/lib/rspec/rails/matchers/routing_matchers.rb @@ -7,28 +7,24 @@ class RouteToMatcher def initialize(scope, *expected) @scope = scope - @expected_options = expected[1] || {} + @expected = expected[1] || {} if Hash === expected[0] - @expected_options.merge!(expected[0]) + @expected.merge!(expected[0]) else controller, action = expected[0].split('#') - @expected_options.merge!(:controller => controller, :action => action) + @expected.merge!(:controller => controller, :action => action) end end - def description - "route #{@verb_to_path_map.inspect} to #{@expected_options.inspect}" - end - # @api private def matches?(verb_to_path_map) - @verb_to_path_map = verb_to_path_map + @actual = @verb_to_path_map = verb_to_path_map # assert_recognizes does not consider ActionController::RoutingError an # assertion failure, so we have to capture that and Assertion here. match_unless_raises ActiveSupport::TestCase::Assertion, ActionController::RoutingError do path, query = *verb_to_path_map.values.first.split('?') @scope.assert_recognizes( - @expected_options, + @expected, {:method => verb_to_path_map.keys.first, :path => path}, Rack::Utils::parse_query(query) ) @@ -39,6 +35,10 @@ def matches?(verb_to_path_map) def failure_message_for_should rescued_exception.message end + + def description + "route #{@actual.inspect} to #{@expected.inspect}" + end end # Delegates to `assert_recognizes`. Supports short-hand controller/action @@ -67,7 +67,7 @@ def initialize(scope) # @api private def matches?(path) - super(path) + @actual = path match_unless_raises ActionController::RoutingError do @routing_options = @scope.routes.recognize_path( path.values.first, :method => path.keys.first @@ -75,9 +75,12 @@ def matches?(path) end end - # @api private + def failure_message_for_should + "expected #{@actual.inspect} to be routable" + end + def failure_message_for_should_not - "expected #{actual.inspect} not to be routable, but it routes to #{@routing_options.inspect}" + "expected #{@actual.inspect} not to be routable, but it routes to #{@routing_options.inspect}" end end From 6781841832c51826d3f7855b905746cd7aaff483 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Tue, 22 May 2012 15:06:10 +0200 Subject: [PATCH 05/42] Update obsolete link to fixture documentation --- lib/generators/rspec/model/templates/fixtures.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/rspec/model/templates/fixtures.yml b/lib/generators/rspec/model/templates/fixtures.yml index c21035113e..2602f85583 100644 --- a/lib/generators/rspec/model/templates/fixtures.yml +++ b/lib/generators/rspec/model/templates/fixtures.yml @@ -1,4 +1,4 @@ -# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html <% unless attributes.empty? -%> one: From e458003b67cd88f209ea679e189bcaa98d7edd0c Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Fri, 25 May 2012 15:21:33 -0400 Subject: [PATCH 06/42] Add Code Climate badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1694dface..7cd2044037 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# rspec-rails-2 +# rspec-rails-2 [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/rspec/rspec-rails) rspec-2 for rails-3 with lightweight extensions to each From 4a30681098f897e4408d8ad304680cb7dc00c3d7 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Fri, 25 May 2012 15:23:27 -0500 Subject: [PATCH 07/42] gotta change the cukes too! - Fixes build broken by #547 --- spec/generators/rspec/model/model_generator_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/generators/rspec/model/model_generator_spec.rb b/spec/generators/rspec/model/model_generator_spec.rb index 901a02b111..85a79c1702 100644 --- a/spec/generators/rspec/model/model_generator_spec.rb +++ b/spec/generators/rspec/model/model_generator_spec.rb @@ -33,7 +33,7 @@ describe 'the fixtures' do subject { file('spec/fixtures/posts.yml') } - it { should contain(Regexp.new('# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html')) } + it { should contain(Regexp.new('# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html')) } end end From fd965a22ae8ff194d1a2a20b8d09909aed39658d Mon Sep 17 00:00:00 2001 From: Jack Dempsey Date: Thu, 31 May 2012 00:50:28 -0700 Subject: [PATCH 08/42] built-in scaffold generator already runs the hook for helper --- lib/generators/rspec/scaffold/scaffold_generator.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/generators/rspec/scaffold/scaffold_generator.rb b/lib/generators/rspec/scaffold/scaffold_generator.rb index afdcc44b69..e6aa5360b9 100644 --- a/lib/generators/rspec/scaffold/scaffold_generator.rb +++ b/lib/generators/rspec/scaffold/scaffold_generator.rb @@ -35,11 +35,6 @@ def generate_view_specs copy_view :show end - # Invoke the helper using the controller name (pluralized) - hook_for :helper, :as => :scaffold do |invoked| - invoke invoked, [ controller_name ] - end - def generate_routing_spec return unless options[:routing_specs] From cfca79ed54453f5f8e3cf1b3f6b8df2d1c0b10eb Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Thu, 31 May 2012 21:05:09 -0500 Subject: [PATCH 09/42] Changlog for #551 [ci skip] --- Changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog.md b/Changelog.md index 388c9f38b0..cd6bf4c0cf 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,8 @@ Bug fixes * fix regression introduced in 2.10.0 that broke integration with Devise (https://github.com/rspec/rspec-rails/issues/534) +* remove generation of helper specs when running the scaffold generator, as + Rails already does this (Jack Dempsey) ### 2.10.0 / 2012-05-03 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.9.0...v2.10.0) From ec87acc1505e558f0c51c309b33167121e6fadde Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Thu, 31 May 2012 21:07:06 -0500 Subject: [PATCH 10/42] add travis banner to README [ci skip] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7cd2044037..873490b219 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# rspec-rails-2 [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/rspec/rspec-rails) +# rspec-rails-2 [![Build Status](https://secure.travis-ci.org/rails/rails.png?branch=master)](http://travis-ci.org/rails/rails) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/rspec/rspec-rails) rspec-2 for rails-3 with lightweight extensions to each From 6b03bf8c11814f69c577fa04e135f455ad5a7a3d Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Thu, 31 May 2012 21:33:56 -0500 Subject: [PATCH 11/42] Take two on the travis banner (grabbed the wrong one the first time) [ci skip] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 873490b219..75c605b4a7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# rspec-rails-2 [![Build Status](https://secure.travis-ci.org/rails/rails.png?branch=master)](http://travis-ci.org/rails/rails) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/rspec/rspec-rails) +# rspec-rails-2 [![Build Status](https://secure.travis-ci.org/rspec/rspec-rails.png?branch=master)](http://travis-ci.org/rspec/rspec-rails) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/rspec/rspec-rails) rspec-2 for rails-3 with lightweight extensions to each From 13bf2a4d32165af17da63de605809ad36ac8e20c Mon Sep 17 00:00:00 2001 From: Bryan Ricker Date: Fri, 1 Jun 2012 00:12:59 -0700 Subject: [PATCH 12/42] Update Factory Girl examples to replace deprecated syntax --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 75c605b4a7..02388746d2 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ users like to use extension libraries like FactoryGirl and Capybara: ```ruby describe "home page" do it "displays the user's username after successful login" do - user = Factory(:user, :username => "jdoe", :password => "secret") + user = FactoryGirl.create(:user, :username => "jdoe", :password => "secret") visit "/login" fill_in "Username", :with => "jdoe" fill_in "Password", :with => "secret" @@ -181,7 +181,7 @@ end describe WidgetsController do describe "GET index" do it "assigns all widgets to @widgets" do - widget = Factory(:widget) + widget = FactoryGirl.create(:widget) get :index assigns(:widgets).should eq([widget]) end From 68787f73f77a46e88c6e97eed99f230da54e8709 Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Fri, 1 Jun 2012 23:53:05 -0600 Subject: [PATCH 13/42] Update doc for stub_model --- lib/rspec/rails/mocks.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/rspec/rails/mocks.rb b/lib/rspec/rails/mocks.rb index 86cda62eb5..2ab1ef6166 100644 --- a/lib/rspec/rails/mocks.rb +++ b/lib/rspec/rails/mocks.rb @@ -114,11 +114,11 @@ def self.primary_key; :id; end def @object.is_a?(other) #{model_class}.ancestors.include?(other) end unless #{stubs.has_key?(:is_a?)} - + def @object.kind_of?(other) #{model_class}.ancestors.include?(other) end unless #{stubs.has_key?(:kind_of?)} - + def @object.instance_of?(other) other == #{model_class} end unless #{stubs.has_key?(:instance_of?)} @@ -130,7 +130,7 @@ def @object.__model_class_has_column?(method_name) def @object.respond_to?(method_name, include_private=false) __model_class_has_column?(method_name) ? true : super end unless #{stubs.has_key?(:respond_to?)} - + def @object.method_missing(m, *a, &b) respond_to?(m) ? null_object? ? self : nil : super end @@ -138,7 +138,7 @@ def @object.method_missing(m, *a, &b) def @object.class #{model_class} end unless #{stubs.has_key?(:class)} - + def @object.to_s "#{model_class.name}_#{to_param}" end unless #{stubs.has_key?(:to_s)} @@ -181,12 +181,12 @@ def connection end # Creates an instance of `Model` with `to_param` stubbed using a - # generated value that is unique to each object.. If `Model` is an + # generated value that is unique to each object. If `Model` is an # `ActiveRecord` model, it is prohibited from accessing the database*. # - # For each key in `hash_of_stubs`, if the model has a matching attribute - # (determined by asking it) are simply assigned the submitted values. If - # the model does not have a matching attribute, the key/value pair is + # For each key in `stubs`, if the model has a matching attribute + # (determined by `respond_to?`) it is simply assigned the submitted values. + # If the model does not have a matching attribute, the key/value pair is # assigned as a stub return value using RSpec's mocking/stubbing # framework. # From e09f6e5e1b620981f4a9f4fdd65c98e0b35efd18 Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 2 Jun 2012 00:04:01 -0600 Subject: [PATCH 14/42] Use one-liner for configuration. --- lib/rspec/rails/mocks.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/rspec/rails/mocks.rb b/lib/rspec/rails/mocks.rb index 2ab1ef6166..6aef7254fc 100644 --- a/lib/rspec/rails/mocks.rb +++ b/lib/rspec/rails/mocks.rb @@ -240,7 +240,4 @@ def next_id end end -RSpec.configure do |c| - c.include RSpec::Rails::Mocks -end - +RSpec.configuration.include RSpec::Rails::Mocks From 2a684525df38ebdbfb3fad0501766dbe57d9afd4 Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 2 Jun 2012 01:57:03 -0600 Subject: [PATCH 15/42] Dev: Fix helper_spec.feature from failing after the first run Because we manually include `ApplicationHelper` into the `_view` object, we can't have conflicting method names between the helpers. This is not really something to worry about with user projects: I believe most projects use `helper :all` and/or do not utilize inheritance (include helper in a helper, with conflicting names in `ApplicationHelper`). Fixes #554 --- features/helper_specs/helper_spec.feature | 16 ++++++++-------- lib/rspec/rails/example/helper_example_group.rb | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/features/helper_specs/helper_spec.feature b/features/helper_specs/helper_spec.feature index 26d16755db..5d39fa2e6a 100644 --- a/features/helper_specs/helper_spec.feature +++ b/features/helper_specs/helper_spec.feature @@ -1,5 +1,5 @@ Feature: helper spec - + Helper specs live in `spec/helpers`, or any example group with `:type => :helper`. @@ -12,12 +12,12 @@ Feature: helper spec on the `helper` object. NOTE: helper methods defined in controllers are not included. - + Scenario: helper method that returns a value Given a file named "spec/helpers/application_helper_spec.rb" with: """ require "spec_helper" - + describe ApplicationHelper do describe "#page_title" do it "returns the default title" do @@ -36,7 +36,7 @@ Feature: helper spec """ When I run `rspec spec/helpers/application_helper_spec.rb` Then the examples should all pass - + Scenario: helper method that accesses an instance variable Given a file named "spec/helpers/application_helper_spec.rb" with: """ @@ -68,10 +68,10 @@ Feature: helper spec require "spec_helper" describe WidgetsHelper do - describe "#page_title" do + describe "#widget_title" do it "includes the app name" do - assign(:title, "This Page") - helper.page_title.should eq("The App: This Page") + assign(:title, "This Widget") + helper.widget_title.should eq("The App: This Widget") end end end @@ -87,7 +87,7 @@ Feature: helper spec And a file named "app/helpers/widgets_helper.rb" with: """ module WidgetsHelper - def page_title + def widget_title "#{app_name}: #{@title}" end end diff --git a/lib/rspec/rails/example/helper_example_group.rb b/lib/rspec/rails/example/helper_example_group.rb index e0c842031e..51bab9ae8a 100644 --- a/lib/rspec/rails/example/helper_example_group.rb +++ b/lib/rspec/rails/example/helper_example_group.rb @@ -18,7 +18,7 @@ def determine_default_helper_class(ignore) # mixed in, along with any of the built-in rails helpers. def helper _view.tap do |v| - v.extend(ApplicationHelper) if defined?(ApplicationHelper) + v.singleton_class.send(:include, ApplicationHelper) if defined?(ApplicationHelper) v.assign(view_assigns) end end From 654367d307569e79ea535974c47ba86ca6da4a1e Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 2 Jun 2012 02:00:31 -0600 Subject: [PATCH 16/42] Dev: Forgot to "revert" including ApplicationHelper into the singleton class - `extend` is just fine. --- lib/rspec/rails/example/helper_example_group.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rspec/rails/example/helper_example_group.rb b/lib/rspec/rails/example/helper_example_group.rb index 51bab9ae8a..e0c842031e 100644 --- a/lib/rspec/rails/example/helper_example_group.rb +++ b/lib/rspec/rails/example/helper_example_group.rb @@ -18,7 +18,7 @@ def determine_default_helper_class(ignore) # mixed in, along with any of the built-in rails helpers. def helper _view.tap do |v| - v.singleton_class.send(:include, ApplicationHelper) if defined?(ApplicationHelper) + v.extend(ApplicationHelper) if defined?(ApplicationHelper) v.assign(view_assigns) end end From 8d7cb3a8f25cac028ee50c455c0579d3c1961c40 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Mon, 6 Feb 2012 13:19:44 -0800 Subject: [PATCH 17/42] Use American-English spelling of color as default This brings the generated `.rspec` file in line with the version used in the project: https://github.com/rspec/rspec-rails/blob/master/.rspec --- lib/generators/rspec/install/templates/.rspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/rspec/install/templates/.rspec b/lib/generators/rspec/install/templates/.rspec index 53607ea52b..4e1e0d2f72 100644 --- a/lib/generators/rspec/install/templates/.rspec +++ b/lib/generators/rspec/install/templates/.rspec @@ -1 +1 @@ ---colour +--color From ed03bda9950db03f65aeef10a05d2eebf657060a Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Mon, 6 Feb 2012 13:35:12 -0800 Subject: [PATCH 18/42] Default to run specs in random order to catch order dependencies * Some features still need to run in default order --- features/controller_specs/render_views.feature | 2 +- features/model_specs/transactional_examples.feature | 1 + lib/generators/rspec/install/templates/spec/spec_helper.rb | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/features/controller_specs/render_views.feature b/features/controller_specs/render_views.feature index 931e06b4cd..2fbfa4fb01 100644 --- a/features/controller_specs/render_views.feature +++ b/features/controller_specs/render_views.feature @@ -71,7 +71,7 @@ Feature: render_views end end """ - When I run `rspec spec --format documentation` + When I run `rspec spec --order default --format documentation` Then the output should contain: """ WidgetsController diff --git a/features/model_specs/transactional_examples.feature b/features/model_specs/transactional_examples.feature index 703a581d47..283f8f4e3f 100644 --- a/features/model_specs/transactional_examples.feature +++ b/features/model_specs/transactional_examples.feature @@ -62,6 +62,7 @@ Feature: transactional examples RSpec.configure do |c| c.use_transactional_examples = false + c.order = "default" end describe Widget do diff --git a/lib/generators/rspec/install/templates/spec/spec_helper.rb b/lib/generators/rspec/install/templates/spec/spec_helper.rb index e66d9802c1..0909127823 100644 --- a/lib/generators/rspec/install/templates/spec/spec_helper.rb +++ b/lib/generators/rspec/install/templates/spec/spec_helper.rb @@ -29,4 +29,10 @@ # automatically. This will be the default behavior in future versions of # rspec-rails. config.infer_base_class_for_anonymous_controllers = false + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = "random" end From 0ad477ab1027df1b330006364fb0d6839cdea2d8 Mon Sep 17 00:00:00 2001 From: Andy Lindeman Date: Sat, 2 Jun 2012 08:02:51 -0400 Subject: [PATCH 19/42] Changelog for #501 * Closes #501 --- Changelog.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Changelog.md b/Changelog.md index cd6bf4c0cf..9c528d13b7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,11 @@ +### dev +[full changelog](http://github.com/rspec/rspec-rails/compare/v2.10.1...master) + +Enhancements + +* The generated `spec/spec_helper.rb` sets `config.order = "random"` so that + specs run in random order by default. + ### 2.10.1 / 2012-05-03 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.10.0...v2.10.1) From 6695a580ec2ed54193311baaac84f6358d4e7cbe Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Sat, 2 Jun 2012 15:23:41 -0400 Subject: [PATCH 20/42] renames `render_template` to `have_rendered`. Also aliases to `render_template` for backward compatibility --- Changelog.md | 3 + lib/rspec/rails/matchers.rb | 2 +- .../{render_template.rb => have_rendered.rb} | 6 +- .../rails/matchers/have_rendered_spec.rb | 93 +++++++++++++++++++ .../rails/matchers/render_template_spec.rb | 91 ------------------ 5 files changed, 101 insertions(+), 94 deletions(-) rename lib/rspec/rails/matchers/{render_template.rb => have_rendered.rb} (86%) create mode 100644 spec/rspec/rails/matchers/have_rendered_spec.rb delete mode 100644 spec/rspec/rails/matchers/render_template_spec.rb diff --git a/Changelog.md b/Changelog.md index 9c528d13b7..570a1f302f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,9 @@ Enhancements * The generated `spec/spec_helper.rb` sets `config.order = "random"` so that specs run in random order by default. +* rename `render_template` to `have_rendered` (and alias to `render_template` + for backward compatibility) + ### 2.10.1 / 2012-05-03 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.10.0...v2.10.1) diff --git a/lib/rspec/rails/matchers.rb b/lib/rspec/rails/matchers.rb index b7756bfa81..fefdd9b75d 100644 --- a/lib/rspec/rails/matchers.rb +++ b/lib/rspec/rails/matchers.rb @@ -17,7 +17,7 @@ class AssertionFailedError < StandardError end end -require 'rspec/rails/matchers/render_template' +require 'rspec/rails/matchers/have_rendered' require 'rspec/rails/matchers/redirect_to' require 'rspec/rails/matchers/routing_matchers' require 'rspec/rails/matchers/be_new_record' diff --git a/lib/rspec/rails/matchers/render_template.rb b/lib/rspec/rails/matchers/have_rendered.rb similarity index 86% rename from lib/rspec/rails/matchers/render_template.rb rename to lib/rspec/rails/matchers/have_rendered.rb index 87abef1457..27d6b22be2 100644 --- a/lib/rspec/rails/matchers/render_template.rb +++ b/lib/rspec/rails/matchers/have_rendered.rb @@ -31,9 +31,11 @@ def failure_message_for_should_not # # @example # - # response.should render_template("new") - def render_template(options, message=nil) + # response.should have_rendered("new") + def have_rendered(options, message=nil) RenderTemplateMatcher.new(self, options, message) end + + alias_method :render_template, :have_rendered end end diff --git a/spec/rspec/rails/matchers/have_rendered_spec.rb b/spec/rspec/rails/matchers/have_rendered_spec.rb new file mode 100644 index 0000000000..1339d9c43d --- /dev/null +++ b/spec/rspec/rails/matchers/have_rendered_spec.rb @@ -0,0 +1,93 @@ +require "spec_helper" + +%w[have_rendered render_template].each do |template_expectation| + describe template_expectation do + include RSpec::Rails::Matchers::RenderTemplate + let(:response) { ActionController::TestResponse.new } + + context "given a hash" do + it "delegates to assert_template" do + self.should_receive(:assert_template).with({:this => "hash"}, "this message") + expect("response").to send(template_expectation, {:this => "hash"}, "this message") + end + end + + context "given a string" do + it "delegates to assert_template" do + self.should_receive(:assert_template).with("this string", "this message") + expect("response").to send(template_expectation, "this string", "this message") + end + end + + context "given a symbol" do + it "converts to_s and delegates to assert_template" do + self.should_receive(:assert_template).with("template_name", "this message") + expect("response").to send(template_expectation, :template_name, "this message") + end + end + + context "with should" do + context "when assert_template passes" do + it "passes" do + self.stub!(:assert_template) + expect do + expect(response).to send(template_expectation, "template_name") + end.to_not raise_exception + end + end + + context "when assert_template fails" do + it "uses failure message from assert_template" do + self.stub!(:assert_template) do + raise ActiveSupport::TestCase::Assertion.new("this message") + end + expect do + expect(response).to send(template_expectation, "template_name") + end.to raise_error("this message") + end + end + + context "when fails due to some other exception" do + it "raises that exception" do + self.stub!(:assert_template) do + raise "oops" + end + expect do + expect(response).to send(template_expectation, "template_name") + end.to raise_exception("oops") + end + end + end + + context "with should_not" do + context "when assert_template fails" do + it "passes" do + def assert_template(*) + raise ActiveSupport::TestCase::Assertion.new("this message") + end + expect do + expect(response).to_not send(template_expectation, "template_name") + end.to_not raise_exception + end + end + + context "when assert_template passes" do + it "fails with custom failure message" do + def assert_template(*); end + expect do + expect(response).to_not send(template_expectation, "template_name") + end.to raise_error(/expected not to render \"template_name\", but did/) + end + end + + context "when fails due to some other exception" do + it "raises that exception" do + def assert_template(*); raise "oops"; end + expect do + expect(response).to_not send(template_expectation, "template_name") + end.to raise_exception("oops") + end + end + end + end +end diff --git a/spec/rspec/rails/matchers/render_template_spec.rb b/spec/rspec/rails/matchers/render_template_spec.rb deleted file mode 100644 index b63cf77216..0000000000 --- a/spec/rspec/rails/matchers/render_template_spec.rb +++ /dev/null @@ -1,91 +0,0 @@ -require "spec_helper" - -describe "render_template" do - include RSpec::Rails::Matchers::RenderTemplate - let(:response) { ActionController::TestResponse.new } - - context "given a hash" do - it "delegates to assert_template" do - self.should_receive(:assert_template).with({:this => "hash"}, "this message") - "response".should render_template({:this => "hash"}, "this message") - end - end - - context "given a string" do - it "delegates to assert_template" do - self.should_receive(:assert_template).with("this string", "this message") - "response".should render_template("this string", "this message") - end - end - - context "given a symbol" do - it "converts to_s and delegates to assert_template" do - self.should_receive(:assert_template).with("template_name", "this message") - "response".should render_template(:template_name, "this message") - end - end - - context "with should" do - context "when assert_template passes" do - it "passes" do - self.stub!(:assert_template) - expect do - response.should render_template("template_name") - end.to_not raise_exception - end - end - - context "when assert_template fails" do - it "uses failure message from assert_template" do - self.stub!(:assert_template) do - raise ActiveSupport::TestCase::Assertion.new("this message") - end - expect do - response.should render_template("template_name") - end.to raise_error("this message") - end - end - - context "when fails due to some other exception" do - it "raises that exception" do - self.stub!(:assert_template) do - raise "oops" - end - expect do - response.should render_template("template_name") - end.to raise_exception("oops") - end - end - end - - context "with should_not" do - context "when assert_template fails" do - it "passes" do - def assert_template(*) - raise ActiveSupport::TestCase::Assertion.new("this message") - end - expect do - response.should_not render_template("template_name") - end.to_not raise_exception - end - end - - context "when assert_template passes" do - it "fails with custom failure message" do - def assert_template(*); end - expect do - response.should_not render_template("template_name") - end.to raise_error(/expected not to render \"template_name\", but did/) - end - end - - context "when fails due to some other exception" do - it "raises that exception" do - def assert_template(*); raise "oops"; end - expect do - response.should_not render_template("template_name") - end.to raise_exception("oops") - end - end - end -end From 31c5ab6133e208e516931dd1d8a80322fe8f3279 Mon Sep 17 00:00:00 2001 From: Andy Lindeman Date: Sun, 3 Jun 2012 17:19:20 -0400 Subject: [PATCH 21/42] Explicitly specify the scope of Rails * If another gem defines `Rspec::Rails` before us, `Rails` might qualify to `Rspec::Rails` (at least in 1.9) * Fixes #555 --- Changelog.md | 6 ++++++ lib/generators/rspec.rb | 2 +- lib/generators/rspec/install/install_generator.rb | 2 +- lib/generators/rspec/scaffold/scaffold_generator.rb | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index 570a1f302f..4b1e3fdd5a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,12 @@ ### dev [full changelog](http://github.com/rspec/rspec-rails/compare/v2.10.1...master) +Bug fixes + +* "uninitialized constant" errors are avoided when using using gems like + `rspec-rails-uncommitted` that define `Rspec::Rails` before `rspec-rails` + loads (Andy Lindeman) + Enhancements * The generated `spec/spec_helper.rb` sets `config.order = "random"` so that diff --git a/lib/generators/rspec.rb b/lib/generators/rspec.rb index 3b1d9e4ea5..ef89550581 100644 --- a/lib/generators/rspec.rb +++ b/lib/generators/rspec.rb @@ -2,7 +2,7 @@ module Rspec module Generators - class Base < Rails::Generators::NamedBase + class Base < ::Rails::Generators::NamedBase def self.source_root @_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates')) end diff --git a/lib/generators/rspec/install/install_generator.rb b/lib/generators/rspec/install/install_generator.rb index 76ecc79bad..cb09c490be 100644 --- a/lib/generators/rspec/install/install_generator.rb +++ b/lib/generators/rspec/install/install_generator.rb @@ -1,6 +1,6 @@ module Rspec module Generators - class InstallGenerator < Rails::Generators::Base + class InstallGenerator < ::Rails::Generators::Base desc < :array, :default => [], :banner => "field:type field:type" From 1c451f8cd381c9a602afc249ea32a5057adffaba Mon Sep 17 00:00:00 2001 From: Dan Rasband Date: Mon, 4 Jun 2012 08:28:58 -0600 Subject: [PATCH 22/42] Tweak alternate app integration This commit removes most if-statements from the example groups, consolidating to a global method called `at_least_rails_3_1`. It also adds filters to the rspec tests and changes engine_support.rb to application.rb. --- lib/rspec/rails.rb | 6 ++++- lib/rspec/rails/application.rb | 13 ++++++++++ lib/rspec/rails/engine_support.rb | 11 --------- .../rails/example/controller_example_group.rb | 6 +---- .../rails/example/mailer_example_group.rb | 6 +---- .../rails/example/request_example_group.rb | 12 ++-------- .../rails/example/routing_example_group.rb | 6 +---- spec/rspec/rails/configuration_spec.rb | 24 +++++-------------- .../example/controller_example_group_spec.rb | 21 +++++----------- .../example/mailer_example_group_spec.rb | 18 ++++---------- .../example/request_example_group_spec.rb | 18 ++++---------- .../example/routing_example_group_spec.rb | 23 ++++++------------ spec/spec_helper.rb | 5 +++- 13 files changed, 56 insertions(+), 113 deletions(-) create mode 100644 lib/rspec/rails/application.rb delete mode 100644 lib/rspec/rails/engine_support.rb diff --git a/lib/rspec/rails.rb b/lib/rspec/rails.rb index fc4e3dc10a..6dfa00c805 100644 --- a/lib/rspec/rails.rb +++ b/lib/rspec/rails.rb @@ -5,6 +5,10 @@ c.backtrace_clean_patterns << /lib\/rspec\/rails/ end +def at_least_rails_3_1? + Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') +end + require 'rspec/rails/extensions' require 'rspec/rails/view_rendering' require 'rspec/rails/adapters' @@ -15,4 +19,4 @@ require 'rspec/rails/example' require 'rspec/rails/vendor/capybara' require 'rspec/rails/vendor/webrat' -require 'rspec/rails/engine_support' +require 'rspec/rails/application' diff --git a/lib/rspec/rails/application.rb b/lib/rspec/rails/application.rb new file mode 100644 index 0000000000..7051637d51 --- /dev/null +++ b/lib/rspec/rails/application.rb @@ -0,0 +1,13 @@ +module RSpec + module Rails + module Application + RSpec.configuration.add_setting :application, :default => ::Rails.application + + # unless at_least_rails_3_1? + # # def RSpec.configuration.application=(*) + # # raise "Setting the application is only supported on Rails 3.1 and above." + # # end + # end + end + end +end diff --git a/lib/rspec/rails/engine_support.rb b/lib/rspec/rails/engine_support.rb deleted file mode 100644 index 636d91c5e6..0000000000 --- a/lib/rspec/rails/engine_support.rb +++ /dev/null @@ -1,11 +0,0 @@ -if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - module RSpec - module Rails - module EngineSupport - RSpec::configure do |config| - config.add_setting :application, :default => ::Rails.application - end - end - end - end -end diff --git a/lib/rspec/rails/example/controller_example_group.rb b/lib/rspec/rails/example/controller_example_group.rb index 8ca9824457..92e76d5bca 100644 --- a/lib/rspec/rails/example/controller_example_group.rb +++ b/lib/rspec/rails/example/controller_example_group.rb @@ -120,11 +120,7 @@ def method_missing(method, *args, &block) metadata[:type] = :controller before do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - @routes = RSpec.configuration.application.routes - else - @routes = ::Rails.application.routes - end + @routes = RSpec.configuration.application.routes ActionController::Base.allow_forgery_protection = false end end diff --git a/lib/rspec/rails/example/mailer_example_group.rb b/lib/rspec/rails/example/mailer_example_group.rb index 257058d82f..4ebb8bb959 100644 --- a/lib/rspec/rails/example/mailer_example_group.rb +++ b/lib/rspec/rails/example/mailer_example_group.rb @@ -7,11 +7,7 @@ module MailerExampleGroup included do metadata[:type] = :mailer - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - include RSpec.configuration.application.routes.url_helpers - else - include ::Rails.application.routes.url_helpers - end + include RSpec.configuration.application.routes.url_helpers options = ::Rails.configuration.action_mailer.default_url_options options.each { |key, value| default_url_options[key] = value } if options end diff --git a/lib/rspec/rails/example/request_example_group.rb b/lib/rspec/rails/example/request_example_group.rb index 1db2a94bf2..df8160009c 100644 --- a/lib/rspec/rails/example/request_example_group.rb +++ b/lib/rspec/rails/example/request_example_group.rb @@ -9,22 +9,14 @@ module RequestExampleGroup include ActionController::TemplateAssertions def app - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - return RSpec.configuration.application - else - return ::Rails.application - end + return RSpec.configuration.application end included do metadata[:type] = :request before do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - @routes = RSpec.configuration.application.routes - else - @routes = ::Rails.application.routes - end + @routes = RSpec.configuration.application.routes end end end diff --git a/lib/rspec/rails/example/routing_example_group.rb b/lib/rspec/rails/example/routing_example_group.rb index bb07c5fb14..0e11ac6216 100644 --- a/lib/rspec/rails/example/routing_example_group.rb +++ b/lib/rspec/rails/example/routing_example_group.rb @@ -12,11 +12,7 @@ module RoutingExampleGroup metadata[:type] = :routing before do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - @routes = RSpec.configuration.application.routes - else - @routes = ::Rails.application.routes - end + @routes = RSpec.configuration.application.routes end end diff --git a/spec/rspec/rails/configuration_spec.rb b/spec/rspec/rails/configuration_spec.rb index 323cd140e8..4b5077494d 100644 --- a/spec/rspec/rails/configuration_spec.rb +++ b/spec/rspec/rails/configuration_spec.rb @@ -29,35 +29,23 @@ context "default" do it "is Rails.application by default" do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - RSpec.configuration.application.should eq(::Rails.application) - else - expect { RSpec.configuration.application }.should raise_error - end + RSpec.configuration.application.should eq(::Rails.application) end end - context "custom rack application" do + context "custom rack application", :at_least_rails_3_1 do before do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - @orig_application = RSpec.configuration.application - end + @orig_application = RSpec.configuration.application end after do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - RSpec.configuration.application = @orig_application - end + RSpec.configuration.application = @orig_application end it "allows for custom application" do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - RSpec.configuration.application = RSpec::EngineExample - RSpec.configuration.application.should eq(RSpec::EngineExample) - else - expect { RSpec.configuration.application = RSpec::EngineExample }.should raise_error - end + RSpec.configuration.application = RSpec::EngineExample + RSpec.configuration.application.should eq(RSpec::EngineExample) end end diff --git a/spec/rspec/rails/example/controller_example_group_spec.rb b/spec/rspec/rails/example/controller_example_group_spec.rb index 95a47d0146..db7eba0263 100644 --- a/spec/rspec/rails/example/controller_example_group_spec.rb +++ b/spec/rspec/rails/example/controller_example_group_spec.rb @@ -97,18 +97,14 @@ module RSpec::Rails end end - describe "#application" do + describe "#application", :at_least_rails_3_1 do before do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - @orig_application = RSpec.configuration.application - RSpec.configuration.application = RSpec::EngineExample - end + @orig_application = RSpec.configuration.application + RSpec.configuration.application = RSpec::EngineExample end after do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - RSpec.configuration.application = @orig_application - end + RSpec.configuration.application = @orig_application end it "still delegates name routes to underlying controller" do @@ -118,13 +114,8 @@ module RSpec::Rails example = group.new example.stub(:controller => controller) - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - example.instance_variable_set(:@orig_routes, RSpec.configuration.application.routes) - example.bars_path.should eq('/foos') - else - example.instance_variable_set(:@orig_routes, ::Rails.application.routes) - expect { example.bars_path }.should raise_error - end + example.instance_variable_set(:@orig_routes, RSpec.configuration.application.routes) + example.bars_path.should eq('/foos') end end end diff --git a/spec/rspec/rails/example/mailer_example_group_spec.rb b/spec/rspec/rails/example/mailer_example_group_spec.rb index 61706a55e1..e3413d4f3b 100644 --- a/spec/rspec/rails/example/mailer_example_group_spec.rb +++ b/spec/rspec/rails/example/mailer_example_group_spec.rb @@ -18,18 +18,14 @@ module ::Rails; end group.metadata[:type].should eq(:mailer) end - describe "custom application" do + describe "custom application", :at_least_rails_3_1 do before do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - @orig_application = RSpec.configuration.application - RSpec.configuration.application = RSpec::EngineExample - end + @orig_application = RSpec.configuration.application + RSpec.configuration.application = RSpec::EngineExample end after do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - RSpec.configuration.application = @orig_application - end + RSpec.configuration.application = @orig_application end it "should include custom application's url helpers" do @@ -38,11 +34,7 @@ module ::Rails; end end example = group.new - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - example.bars_path.should == '/bars' - else - expect { example.bars_path }.should raise_error - end + example.bars_path.should == '/bars' end end end diff --git a/spec/rspec/rails/example/request_example_group_spec.rb b/spec/rspec/rails/example/request_example_group_spec.rb index 2e127adb51..6e99751518 100644 --- a/spec/rspec/rails/example/request_example_group_spec.rb +++ b/spec/rspec/rails/example/request_example_group_spec.rb @@ -14,18 +14,14 @@ module RSpec::Rails group.metadata[:type].should eq(:request) end - describe "#app" do + describe "#app", :at_least_rails_3_1 do before do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - @orig_application = RSpec.configuration.application - RSpec.configuration.application = RSpec::EngineExample - end + @orig_application = RSpec.configuration.application + RSpec.configuration.application = RSpec::EngineExample end after do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - RSpec.configuration.application = @orig_application - end + RSpec.configuration.application = @orig_application end it "sets app as custom application" do @@ -35,11 +31,7 @@ module RSpec::Rails example = group.new - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - example.app.should eq(RSpec::EngineExample) - else - example.app.should eq(::Rails.application) - end + example.app.should eq(RSpec::EngineExample) end end end diff --git a/spec/rspec/rails/example/routing_example_group_spec.rb b/spec/rspec/rails/example/routing_example_group_spec.rb index b41fe2c456..e320b0ae32 100644 --- a/spec/rspec/rails/example/routing_example_group_spec.rb +++ b/spec/rspec/rails/example/routing_example_group_spec.rb @@ -29,18 +29,14 @@ module RSpec::Rails end end - describe "custom application routes" do + describe "custom application routes", :at_least_rails_3_1 do before do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - @orig_application = RSpec.configuration.application - RSpec.configuration.application = RSpec::EngineExample - end + @orig_application = RSpec.configuration.application + RSpec.configuration.application = RSpec::EngineExample end after do - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - RSpec.configuration.application = @orig_application - end + RSpec.configuration.application = @orig_application end it "provides routes of custom application" do @@ -50,14 +46,9 @@ module RSpec::Rails example = group.new - if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') - # Because this relies on before hooks, I have to stub this in. - example.stub(:routes => RSpec.configuration.application.routes) - example.bars_path.should == "/bars" - else - example.stub(:routes => ::Rails.application.routes) - expect { example.bars_path }.should raise_error - end + # Because this relies on before hooks, I have to stub this in. + example.stub(:routes => RSpec.configuration.application.routes) + example.bars_path.should == "/bars" end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e600660c26..8c5ccb497f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,7 +16,7 @@ def self.run_all(reporter=nil) end end -if Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') +if at_least_rails_3_1? RSpec::EngineExample.routes.draw do root :to => "foo#index" resources :bars @@ -26,6 +26,9 @@ def self.run_all(reporter=nil) RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.filter_run :focus + unless at_least_rails_3_1? + config.filter_run_excluding :at_least_rails_3_1 + end config.run_all_when_everything_filtered = true config.before(:each) do @real_world = RSpec.world From b86190c7fb39513d1b84f08666dd7dd57a3a5952 Mon Sep 17 00:00:00 2001 From: Vladimir Strakhov Date: Tue, 5 Jun 2012 11:17:44 +0400 Subject: [PATCH 23/42] Fix typo in Changelog.md --- Changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 4b1e3fdd5a..ddfe8d1cdb 100644 --- a/Changelog.md +++ b/Changelog.md @@ -43,7 +43,7 @@ Bug fixes ### 2.9.0 / 2012-03-17 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.8.1...v2.9.0) -Enhancments +Enhancements * add description method to RouteToMatcher (John Wulff) * Run "db:test:clone_structure" instead of "db:test:prepare" if Active Record's @@ -109,7 +109,7 @@ you'll have to upgrade to rspec-rails-2.8.1 when you upgrade to rails >= [full changelog](http://github.com/rspec/rspec-rails/compare/v2.6.1...v2.7.0) -* Enhancments +* Enhancements * `ActiveRecord::Relation` can use the `=~` matcher (Andy Lindeman) * Make generated controller spec more consistent with regard to ids (Brent J. Nordquist) From f869484d91c9a8c905f2342217082b1230151588 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Wed, 6 Jun 2012 07:19:25 -0500 Subject: [PATCH 24/42] changelog tweaks [ci skip] --- Changelog.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Changelog.md b/Changelog.md index ddfe8d1cdb..8d6eaa3aa8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,12 +1,6 @@ ### dev [full changelog](http://github.com/rspec/rspec-rails/compare/v2.10.1...master) -Bug fixes - -* "uninitialized constant" errors are avoided when using using gems like - `rspec-rails-uncommitted` that define `Rspec::Rails` before `rspec-rails` - loads (Andy Lindeman) - Enhancements * The generated `spec/spec_helper.rb` sets `config.order = "random"` so that @@ -14,6 +8,11 @@ Enhancements * rename `render_template` to `have_rendered` (and alias to `render_template` for backward compatibility) +Bug fixes + +* "uninitialized constant" errors are avoided when using using gems like + `rspec-rails-uncommitted` that define `Rspec::Rails` before `rspec-rails` + loads (Andy Lindeman) ### 2.10.1 / 2012-05-03 [full changelog](http://github.com/rspec/rspec-rails/compare/v2.10.0...v2.10.1) From e795ec0c0ac75a2b5c51234943e89f03fa17f9cd Mon Sep 17 00:00:00 2001 From: Jim Deville Date: Fri, 8 Jun 2012 18:09:11 -0700 Subject: [PATCH 25/42] add features to show how namespaced routes can be matched --- features/routing_specs/README.md | 13 ++++++++ .../routing_specs/route_to_matcher.feature | 32 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/features/routing_specs/README.md b/features/routing_specs/README.md index 533f7a5476..8f0d847d25 100644 --- a/features/routing_specs/README.md +++ b/features/routing_specs/README.md @@ -15,3 +15,16 @@ customized routes, like vanity links, slugs, etc. They are also valuable for routes that should not be available: { :delete => "/accounts/37" }.should_not be_routable + +## Specifying matched routes + +When using the `#route_to` matcher, you can specify the expected route using a +hash or a string, and it will be parsed: + + route_to("controller#action") + route_to("namespaced/controller#action") + route_to(:controller => "controller", + :action => "action", + :params => "params") + route_to(:controller => "namespaced/controller", + :action => "action") diff --git a/features/routing_specs/route_to_matcher.feature b/features/routing_specs/route_to_matcher.feature index 08ddb68e86..59e3400b0d 100644 --- a/features/routing_specs/route_to_matcher.feature +++ b/features/routing_specs/route_to_matcher.feature @@ -56,3 +56,35 @@ Feature: route_to matcher When I run `rspec spec/routing/widgets_routing_spec.rb` Then the output should contain "1 failure" + + Scenario: route spec for a namespaced route with shortcut specifier + Given a file named "spec/routing/admin_routing_spec.rb" with: + """ + require "spec_helper" + + describe "routes for Widgets" do + it "routes /admin/accounts to the admin/accounts controller" do + get("/admin/accounts"). + should route_to("admin/accounts#index") + end + end + """ + + When I run `rspec spec/routing/admin_routing_spec.rb` + Then the examples should all pass + + Scenario: route spec for a namespaced route with verbose specifier + Given a file named "spec/routing/admin_routing_spec.rb" with: + """ + require "spec_helper" + + describe "routes for Widgets" do + it "routes /admin/accounts to the admin/accounts controller" do + get("/admin/accounts"). + should route_to(:controller => "admin/accounts", :action => "index") + end + end + """ + + When I run `rspec spec/routing/admin_routing_spec.rb` + Then the examples should all pass \ No newline at end of file From 9abdc0a588a78d3cd50bb58ce719ce72f9af34e1 Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 9 Jun 2012 00:04:00 -0600 Subject: [PATCH 26/42] Revert change to features/routing_specs/README.md - the documentation for #route_to is sufficient --- features/routing_specs/README.md | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/features/routing_specs/README.md b/features/routing_specs/README.md index 8f0d847d25..0473c3df56 100644 --- a/features/routing_specs/README.md +++ b/features/routing_specs/README.md @@ -14,17 +14,4 @@ customized routes, like vanity links, slugs, etc. They are also valuable for routes that should not be available: - { :delete => "/accounts/37" }.should_not be_routable - -## Specifying matched routes - -When using the `#route_to` matcher, you can specify the expected route using a -hash or a string, and it will be parsed: - - route_to("controller#action") - route_to("namespaced/controller#action") - route_to(:controller => "controller", - :action => "action", - :params => "params") - route_to(:controller => "namespaced/controller", - :action => "action") + { :delete => "/accounts/37" }.should_not be_routable \ No newline at end of file From ab6a23d2b34b90bc1c3b486197e8c00e4c9cb42b Mon Sep 17 00:00:00 2001 From: Ben Morris Date: Thu, 21 Jun 2012 16:57:31 -0300 Subject: [PATCH 27/42] Removed the extra spaces between methods. They have been mocking me for months. --- lib/generators/rspec/scaffold/templates/controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/rspec/scaffold/templates/controller_spec.rb b/lib/generators/rspec/scaffold/templates/controller_spec.rb index ccc259642e..e951980675 100644 --- a/lib/generators/rspec/scaffold/templates/controller_spec.rb +++ b/lib/generators/rspec/scaffold/templates/controller_spec.rb @@ -26,7 +26,7 @@ def valid_attributes {} end - + # This should return the minimal set of values that should be in the session # in order to pass any filters (e.g. authentication) defined in # <%= controller_class_name %>Controller. Be sure to keep this updated too. From b694543c858796f1ab2fb2e71288f55f233c946c Mon Sep 17 00:00:00 2001 From: Dan Rasband Date: Fri, 22 Jun 2012 09:38:28 -0600 Subject: [PATCH 28/42] Raise error for Rails 3.0 Adds an override of Rails.configuration.application=(*) setter to raise an error when Rails.configuration.application is set in Rails 3.0. Also moves at_least_rails_3_1? method to the RSpec::Rails module as a public module method. --- lib/rspec-rails.rb | 4 ++++ lib/rspec/rails.rb | 4 ---- lib/rspec/rails/application.rb | 15 ++++++++++----- spec/rspec/rails/configuration_spec.rb | 4 ++++ spec/spec_helper.rb | 6 ++++-- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/rspec-rails.rb b/lib/rspec-rails.rb index 004457b01e..e1c829efcf 100644 --- a/lib/rspec-rails.rb +++ b/lib/rspec-rails.rb @@ -1,5 +1,9 @@ module RSpec module Rails + def self.at_least_rails_3_1? + Gem::Version.new(::Rails.version) >= Gem::Version.new('3.1.0') + end + class Railtie < ::Rails::Railtie # Rails-3.0.1 requires config.app_generators instead of 3.0.0's config.generators generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators diff --git a/lib/rspec/rails.rb b/lib/rspec/rails.rb index 6dfa00c805..e3bba91e63 100644 --- a/lib/rspec/rails.rb +++ b/lib/rspec/rails.rb @@ -5,10 +5,6 @@ c.backtrace_clean_patterns << /lib\/rspec\/rails/ end -def at_least_rails_3_1? - Gem::Version.new(Rails.version) >= Gem::Version.new('3.1.0') -end - require 'rspec/rails/extensions' require 'rspec/rails/view_rendering' require 'rspec/rails/adapters' diff --git a/lib/rspec/rails/application.rb b/lib/rspec/rails/application.rb index 7051637d51..f2427d43d3 100644 --- a/lib/rspec/rails/application.rb +++ b/lib/rspec/rails/application.rb @@ -1,13 +1,18 @@ +require 'rspec-rails' module RSpec module Rails module Application RSpec.configuration.add_setting :application, :default => ::Rails.application - # unless at_least_rails_3_1? - # # def RSpec.configuration.application=(*) - # # raise "Setting the application is only supported on Rails 3.1 and above." - # # end - # end + # Raise an error when setting application in Rails < 3.1 + unless RSpec::Rails.at_least_rails_3_1? + class << RSpec.configuration + def application=(*) + raise "Setting the application is only supported on Rails 3.1 and above." + end + end + end + end end end diff --git a/spec/rspec/rails/configuration_spec.rb b/spec/rspec/rails/configuration_spec.rb index 4b5077494d..04815e1cc7 100644 --- a/spec/rspec/rails/configuration_spec.rb +++ b/spec/rspec/rails/configuration_spec.rb @@ -32,6 +32,10 @@ RSpec.configuration.application.should eq(::Rails.application) end + it "should raise an error for Rails 3.0", :not_at_least_rails_3_1 do + expect { RSpec.configuration.application = ::Rails.application }.should raise_error + end + end context "custom rack application", :at_least_rails_3_1 do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8c5ccb497f..365015dce0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,7 +16,7 @@ def self.run_all(reporter=nil) end end -if at_least_rails_3_1? +if RSpec::Rails.at_least_rails_3_1? RSpec::EngineExample.routes.draw do root :to => "foo#index" resources :bars @@ -26,7 +26,9 @@ def self.run_all(reporter=nil) RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.filter_run :focus - unless at_least_rails_3_1? + if RSpec::Rails.at_least_rails_3_1? + config.filter_run_excluding :not_at_least_rails_3_1 + else config.filter_run_excluding :at_least_rails_3_1 end config.run_all_when_everything_filtered = true From f067d8f05694b8da20e247339b2b89cfe2e8a34b Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 23 Jun 2012 11:12:17 -0600 Subject: [PATCH 29/42] Move "at least rails 3.1" method to rspec/rails file. --- lib/rspec-rails.rb | 4 ---- lib/rspec/rails.rb | 10 +++++++++- lib/rspec/rails/application.rb | 5 +---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/rspec-rails.rb b/lib/rspec-rails.rb index e1c829efcf..004457b01e 100644 --- a/lib/rspec-rails.rb +++ b/lib/rspec-rails.rb @@ -1,9 +1,5 @@ module RSpec module Rails - def self.at_least_rails_3_1? - Gem::Version.new(::Rails.version) >= Gem::Version.new('3.1.0') - end - class Railtie < ::Rails::Railtie # Rails-3.0.1 requires config.app_generators instead of 3.0.0's config.generators generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators diff --git a/lib/rspec/rails.rb b/lib/rspec/rails.rb index e3bba91e63..804a919120 100644 --- a/lib/rspec/rails.rb +++ b/lib/rspec/rails.rb @@ -1,10 +1,18 @@ require 'rspec/core' -RSpec::configure do |c| +RSpec.configure do |c| c.backtrace_clean_patterns << /vendor\// c.backtrace_clean_patterns << /lib\/rspec\/rails/ end +module RSpec + module Rails + def self.at_least_rails_3_1? + Gem::Version.new(::Rails.version) >= Gem::Version.new('3.1.0') + end + end +end + require 'rspec/rails/extensions' require 'rspec/rails/view_rendering' require 'rspec/rails/adapters' diff --git a/lib/rspec/rails/application.rb b/lib/rspec/rails/application.rb index f2427d43d3..c5fb3a36ce 100644 --- a/lib/rspec/rails/application.rb +++ b/lib/rspec/rails/application.rb @@ -1,18 +1,15 @@ -require 'rspec-rails' module RSpec module Rails module Application RSpec.configuration.add_setting :application, :default => ::Rails.application - # Raise an error when setting application in Rails < 3.1 unless RSpec::Rails.at_least_rails_3_1? class << RSpec.configuration def application=(*) - raise "Setting the application is only supported on Rails 3.1 and above." + raise 'Setting the application is only supported on Rails 3.1 and above.' end end end - end end end From 454364bd41cbd21c7fd102f31cb9f8d5ee3ccd05 Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 23 Jun 2012 11:15:21 -0600 Subject: [PATCH 30/42] This should be a writer method spec. --- spec/rspec/rails/configuration_spec.rb | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/spec/rspec/rails/configuration_spec.rb b/spec/rspec/rails/configuration_spec.rb index 04815e1cc7..1dbf5f95ae 100644 --- a/spec/rspec/rails/configuration_spec.rb +++ b/spec/rspec/rails/configuration_spec.rb @@ -25,17 +25,8 @@ end describe "#application" do - - context "default" do - - it "is Rails.application by default" do - RSpec.configuration.application.should eq(::Rails.application) - end - - it "should raise an error for Rails 3.0", :not_at_least_rails_3_1 do - expect { RSpec.configuration.application = ::Rails.application }.should raise_error - end - + it "returns Rails.application by default" do + RSpec.configuration.application.should eq(::Rails.application) end context "custom rack application", :at_least_rails_3_1 do @@ -51,7 +42,14 @@ RSpec.configuration.application = RSpec::EngineExample RSpec.configuration.application.should eq(RSpec::EngineExample) end + end + end + describe '#application=' do + context 'for Rails 3.0', :not_at_least_rails_3_1 do + it 'raises an error' do + expect { RSpec.configuration.application = ::Rails.application }.to raise_error + end end end end From 34cbadc21780f00bcdd806dbf112fc17513970bb Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 23 Jun 2012 11:16:39 -0600 Subject: [PATCH 31/42] Move the "drawing of the routes" for the EngineExample to engine_example.rb --- spec/spec_helper.rb | 7 ------- spec/support/engine_example.rb | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 365015dce0..08a403a9c8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,13 +16,6 @@ def self.run_all(reporter=nil) end end -if RSpec::Rails.at_least_rails_3_1? - RSpec::EngineExample.routes.draw do - root :to => "foo#index" - resources :bars - end -end - RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.filter_run :focus diff --git a/spec/support/engine_example.rb b/spec/support/engine_example.rb index 882f747208..839dfea909 100644 --- a/spec/support/engine_example.rb +++ b/spec/support/engine_example.rb @@ -3,4 +3,11 @@ class EngineExample < ::Rails::Engine def self.activate end end + + if RSpec::Rails.at_least_rails_3_1? + EngineExample.routes.draw do + root :to => "foo#index" + resources :bars + end + end end From 1f58ed92258ad2bf10b0b8609a7bedb85d5b8823 Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 23 Jun 2012 12:52:48 -0600 Subject: [PATCH 32/42] Don't need a file for this. --- lib/rspec/rails.rb | 20 +++++++++++++------- lib/rspec/rails/application.rb | 15 --------------- 2 files changed, 13 insertions(+), 22 deletions(-) delete mode 100644 lib/rspec/rails/application.rb diff --git a/lib/rspec/rails.rb b/lib/rspec/rails.rb index 804a919120..64a87447d4 100644 --- a/lib/rspec/rails.rb +++ b/lib/rspec/rails.rb @@ -1,10 +1,5 @@ require 'rspec/core' -RSpec.configure do |c| - c.backtrace_clean_patterns << /vendor\// - c.backtrace_clean_patterns << /lib\/rspec\/rails/ -end - module RSpec module Rails def self.at_least_rails_3_1? @@ -13,6 +8,18 @@ def self.at_least_rails_3_1? end end +RSpec.configure do |config| + config.backtrace_clean_patterns << /vendor\// + config.backtrace_clean_patterns << /lib\/rspec\/rails/ + config.add_setting :application, :default => ::Rails.application + + unless RSpec::Rails.at_least_rails_3_1? + def config.application=(*) + raise 'Setting the application is only supported on Rails 3.1 and above.' + end + end +end + require 'rspec/rails/extensions' require 'rspec/rails/view_rendering' require 'rspec/rails/adapters' @@ -22,5 +29,4 @@ def self.at_least_rails_3_1? require 'rspec/rails/module_inclusion' require 'rspec/rails/example' require 'rspec/rails/vendor/capybara' -require 'rspec/rails/vendor/webrat' -require 'rspec/rails/application' +require 'rspec/rails/vendor/webrat' \ No newline at end of file diff --git a/lib/rspec/rails/application.rb b/lib/rspec/rails/application.rb deleted file mode 100644 index c5fb3a36ce..0000000000 --- a/lib/rspec/rails/application.rb +++ /dev/null @@ -1,15 +0,0 @@ -module RSpec - module Rails - module Application - RSpec.configuration.add_setting :application, :default => ::Rails.application - - unless RSpec::Rails.at_least_rails_3_1? - class << RSpec.configuration - def application=(*) - raise 'Setting the application is only supported on Rails 3.1 and above.' - end - end - end - end - end -end From b4b26085cc3f403f5f400a28e4258e75be65909e Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 23 Jun 2012 20:59:24 -0600 Subject: [PATCH 33/42] Don't need this example - it spec's an accessor. --- spec/rspec/rails/configuration_spec.rb | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/spec/rspec/rails/configuration_spec.rb b/spec/rspec/rails/configuration_spec.rb index 1dbf5f95ae..788740d285 100644 --- a/spec/rspec/rails/configuration_spec.rb +++ b/spec/rspec/rails/configuration_spec.rb @@ -28,21 +28,6 @@ it "returns Rails.application by default" do RSpec.configuration.application.should eq(::Rails.application) end - - context "custom rack application", :at_least_rails_3_1 do - before do - @orig_application = RSpec.configuration.application - end - - after do - RSpec.configuration.application = @orig_application - end - - it "allows for custom application" do - RSpec.configuration.application = RSpec::EngineExample - RSpec.configuration.application.should eq(RSpec::EngineExample) - end - end end describe '#application=' do From 489bebc11ffbd4e4bc90251e7159bf4f14311c5c Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 23 Jun 2012 21:11:41 -0600 Subject: [PATCH 34/42] changelog --- Changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Changelog.md b/Changelog.md index 8d6eaa3aa8..7e08242ce4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,9 @@ Enhancements specs run in random order by default. * rename `render_template` to `have_rendered` (and alias to `render_template` for backward compatibility) +* Spec an engine instead of the Rails app: + `Rails.configuration.application = MyEngine` - default is `Rails.application` + (Dan Rasband @danrasban) Bug fixes From 2fc6473e4d49bcfbe617c1a5a7272a0e7fb22e21 Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 23 Jun 2012 21:30:02 -0600 Subject: [PATCH 35/42] No need for explicit return statement. --- lib/rspec/rails/example/request_example_group.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rspec/rails/example/request_example_group.rb b/lib/rspec/rails/example/request_example_group.rb index df8160009c..602701d14b 100644 --- a/lib/rspec/rails/example/request_example_group.rb +++ b/lib/rspec/rails/example/request_example_group.rb @@ -9,7 +9,7 @@ module RequestExampleGroup include ActionController::TemplateAssertions def app - return RSpec.configuration.application + RSpec.configuration.application end included do From 1a9d160150b57bd13eb21bcd1eddf12b182239a5 Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 23 Jun 2012 21:30:40 -0600 Subject: [PATCH 36/42] Nothing "custom" about this. --- .../rails/example/request_example_group_spec.rb | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/spec/rspec/rails/example/request_example_group_spec.rb b/spec/rspec/rails/example/request_example_group_spec.rb index 6e99751518..d00d32bde2 100644 --- a/spec/rspec/rails/example/request_example_group_spec.rb +++ b/spec/rspec/rails/example/request_example_group_spec.rb @@ -14,24 +14,15 @@ module RSpec::Rails group.metadata[:type].should eq(:request) end - describe "#app", :at_least_rails_3_1 do - before do - @orig_application = RSpec.configuration.application - RSpec.configuration.application = RSpec::EngineExample - end - - after do - RSpec.configuration.application = @orig_application - end - - it "sets app as custom application" do + describe '#app' do + it 'returns the RSpec.configuration.application' do group = RSpec::Core::ExampleGroup.describe do include RequestExampleGroup end example = group.new - example.app.should eq(RSpec::EngineExample) + example.app.should eq(RSpec.configuration.application) end end end From cf11980622f5f1d353234ade75efe2a7bab1da93 Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 23 Jun 2012 21:40:34 -0600 Subject: [PATCH 37/42] Move the "application swapping" to an `around` filter in the spec_helper. --- .../rails/example/controller_example_group_spec.rb | 13 ++----------- .../rails/example/mailer_example_group_spec.rb | 11 +---------- .../rails/example/routing_example_group_spec.rb | 14 ++------------ spec/spec_helper.rb | 6 ++++++ 4 files changed, 11 insertions(+), 33 deletions(-) diff --git a/spec/rspec/rails/example/controller_example_group_spec.rb b/spec/rspec/rails/example/controller_example_group_spec.rb index db7eba0263..51a52e4283 100644 --- a/spec/rspec/rails/example/controller_example_group_spec.rb +++ b/spec/rspec/rails/example/controller_example_group_spec.rb @@ -97,17 +97,8 @@ module RSpec::Rails end end - describe "#application", :at_least_rails_3_1 do - before do - @orig_application = RSpec.configuration.application - RSpec.configuration.application = RSpec::EngineExample - end - - after do - RSpec.configuration.application = @orig_application - end - - it "still delegates name routes to underlying controller" do + describe "custom application", :at_least_rails_3_1 do + it "delegates named routes to the underlying controller" do controller = double('controller') controller.stub(:bars_path).and_return('/foos') diff --git a/spec/rspec/rails/example/mailer_example_group_spec.rb b/spec/rspec/rails/example/mailer_example_group_spec.rb index e3413d4f3b..5d8c762d8c 100644 --- a/spec/rspec/rails/example/mailer_example_group_spec.rb +++ b/spec/rspec/rails/example/mailer_example_group_spec.rb @@ -19,16 +19,7 @@ module ::Rails; end end describe "custom application", :at_least_rails_3_1 do - before do - @orig_application = RSpec.configuration.application - RSpec.configuration.application = RSpec::EngineExample - end - - after do - RSpec.configuration.application = @orig_application - end - - it "should include custom application's url helpers" do + it "includes the custom application's url helpers" do group = RSpec::Core::ExampleGroup.describe do include MailerExampleGroup end diff --git a/spec/rspec/rails/example/routing_example_group_spec.rb b/spec/rspec/rails/example/routing_example_group_spec.rb index e320b0ae32..d5853b2c62 100644 --- a/spec/rspec/rails/example/routing_example_group_spec.rb +++ b/spec/rspec/rails/example/routing_example_group_spec.rb @@ -29,17 +29,8 @@ module RSpec::Rails end end - describe "custom application routes", :at_least_rails_3_1 do - before do - @orig_application = RSpec.configuration.application - RSpec.configuration.application = RSpec::EngineExample - end - - after do - RSpec.configuration.application = @orig_application - end - - it "provides routes of custom application" do + describe "custom application", :at_least_rails_3_1 do + it "provides routes of the custom application" do group = RSpec::Core::ExampleGroup.describe do include RoutingExampleGroup end @@ -50,7 +41,6 @@ module RSpec::Rails example.stub(:routes => RSpec.configuration.application.routes) example.bars_path.should == "/bars" end - end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 08a403a9c8..3af24ef9b6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -21,6 +21,12 @@ def self.run_all(reporter=nil) config.filter_run :focus if RSpec::Rails.at_least_rails_3_1? config.filter_run_excluding :not_at_least_rails_3_1 + config.around(:each, :at_least_rails_3_1) do |example| + orig_application = RSpec.configuration.application + RSpec.configuration.application = RSpec::EngineExample + example.run + RSpec.configuration.application = orig_application + end else config.filter_run_excluding :at_least_rails_3_1 end From dbbec246c2dbe1436eb77c8cbfe8b350929ecb2e Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 23 Jun 2012 21:54:58 -0600 Subject: [PATCH 38/42] After thinking about it, there is nothing "engine specific" about any of this new code. Therefore, no need to have engine specific specs. --- spec/rspec/rails/configuration_spec.rb | 2 +- .../rails/example/controller_example_group_spec.rb | 13 ------------- .../rails/example/mailer_example_group_spec.rb | 11 ----------- .../rails/example/routing_example_group_spec.rb | 14 -------------- spec/spec_helper.rb | 11 ----------- spec/support/engine_example.rb | 13 ------------- 6 files changed, 1 insertion(+), 63 deletions(-) delete mode 100644 spec/support/engine_example.rb diff --git a/spec/rspec/rails/configuration_spec.rb b/spec/rspec/rails/configuration_spec.rb index 788740d285..804ad52480 100644 --- a/spec/rspec/rails/configuration_spec.rb +++ b/spec/rspec/rails/configuration_spec.rb @@ -31,7 +31,7 @@ end describe '#application=' do - context 'for Rails 3.0', :not_at_least_rails_3_1 do + context 'for Rails 3.0', :unless => RSpec::Rails.at_least_rails_3_1? do it 'raises an error' do expect { RSpec.configuration.application = ::Rails.application }.to raise_error end diff --git a/spec/rspec/rails/example/controller_example_group_spec.rb b/spec/rspec/rails/example/controller_example_group_spec.rb index 51a52e4283..f5e390edd1 100644 --- a/spec/rspec/rails/example/controller_example_group_spec.rb +++ b/spec/rspec/rails/example/controller_example_group_spec.rb @@ -96,18 +96,5 @@ module RSpec::Rails controller_class.superclass.should eq(ApplicationController) end end - - describe "custom application", :at_least_rails_3_1 do - it "delegates named routes to the underlying controller" do - controller = double('controller') - controller.stub(:bars_path).and_return('/foos') - - example = group.new - example.stub(:controller => controller) - - example.instance_variable_set(:@orig_routes, RSpec.configuration.application.routes) - example.bars_path.should eq('/foos') - end - end end end diff --git a/spec/rspec/rails/example/mailer_example_group_spec.rb b/spec/rspec/rails/example/mailer_example_group_spec.rb index 5d8c762d8c..c01c4fe540 100644 --- a/spec/rspec/rails/example/mailer_example_group_spec.rb +++ b/spec/rspec/rails/example/mailer_example_group_spec.rb @@ -17,16 +17,5 @@ module ::Rails; end end group.metadata[:type].should eq(:mailer) end - - describe "custom application", :at_least_rails_3_1 do - it "includes the custom application's url helpers" do - group = RSpec::Core::ExampleGroup.describe do - include MailerExampleGroup - end - - example = group.new - example.bars_path.should == '/bars' - end - end end end diff --git a/spec/rspec/rails/example/routing_example_group_spec.rb b/spec/rspec/rails/example/routing_example_group_spec.rb index d5853b2c62..4c3ed0c543 100644 --- a/spec/rspec/rails/example/routing_example_group_spec.rb +++ b/spec/rspec/rails/example/routing_example_group_spec.rb @@ -28,19 +28,5 @@ module RSpec::Rails example.foo_path.should == "foo" end end - - describe "custom application", :at_least_rails_3_1 do - it "provides routes of the custom application" do - group = RSpec::Core::ExampleGroup.describe do - include RoutingExampleGroup - end - - example = group.new - - # Because this relies on before hooks, I have to stub this in. - example.stub(:routes => RSpec.configuration.application.routes) - example.bars_path.should == "/bars" - end - end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3af24ef9b6..13373f1a65 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -19,17 +19,6 @@ def self.run_all(reporter=nil) RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.filter_run :focus - if RSpec::Rails.at_least_rails_3_1? - config.filter_run_excluding :not_at_least_rails_3_1 - config.around(:each, :at_least_rails_3_1) do |example| - orig_application = RSpec.configuration.application - RSpec.configuration.application = RSpec::EngineExample - example.run - RSpec.configuration.application = orig_application - end - else - config.filter_run_excluding :at_least_rails_3_1 - end config.run_all_when_everything_filtered = true config.before(:each) do @real_world = RSpec.world diff --git a/spec/support/engine_example.rb b/spec/support/engine_example.rb deleted file mode 100644 index 839dfea909..0000000000 --- a/spec/support/engine_example.rb +++ /dev/null @@ -1,13 +0,0 @@ -module RSpec - class EngineExample < ::Rails::Engine - def self.activate - end - end - - if RSpec::Rails.at_least_rails_3_1? - EngineExample.routes.draw do - root :to => "foo#index" - resources :bars - end - end -end From ebd891f5f833b1a87809bd7b4b49f2a16c6a09b9 Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Sat, 23 Jun 2012 21:57:02 -0600 Subject: [PATCH 39/42] Better changelog message. --- Changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index 7e08242ce4..943ec47bb6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,7 +7,7 @@ Enhancements specs run in random order by default. * rename `render_template` to `have_rendered` (and alias to `render_template` for backward compatibility) -* Spec an engine instead of the Rails app: +* Specify a different application (e.g. an engine) instead of the Rails app: `Rails.configuration.application = MyEngine` - default is `Rails.application` (Dan Rasband @danrasban) From 91870eda039d9fcc2b44ec6b7910ec3bd3d835f6 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Tue, 26 Jun 2012 06:31:15 -0400 Subject: [PATCH 40/42] convert matchers to subclass BaseMatcher class --- lib/rspec/rails/matchers/be_a_new.rb | 3 +-- lib/rspec/rails/matchers/be_new_record.rb | 3 +-- lib/rspec/rails/matchers/have_rendered.rb | 3 +-- lib/rspec/rails/matchers/redirect_to.rb | 3 +-- lib/rspec/rails/matchers/routing_matchers.rb | 6 ++---- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/lib/rspec/rails/matchers/be_a_new.rb b/lib/rspec/rails/matchers/be_a_new.rb index 33837f4be9..8bcdd99dd6 100644 --- a/lib/rspec/rails/matchers/be_a_new.rb +++ b/lib/rspec/rails/matchers/be_a_new.rb @@ -1,6 +1,5 @@ module RSpec::Rails::Matchers - class BeANew - include RSpec::Matchers::BuiltIn::BaseMatcher + class BeANew < RSpec::Matchers::BuiltIn::BaseMatcher def initialize(expected) @expected = expected diff --git a/lib/rspec/rails/matchers/be_new_record.rb b/lib/rspec/rails/matchers/be_new_record.rb index 890f3bb304..2ff9709058 100644 --- a/lib/rspec/rails/matchers/be_new_record.rb +++ b/lib/rspec/rails/matchers/be_new_record.rb @@ -1,6 +1,5 @@ module RSpec::Rails::Matchers - class BeANewRecord - include RSpec::Matchers::BuiltIn::BaseMatcher + class BeANewRecord < RSpec::Matchers::BuiltIn::BaseMatcher # @api private def matches?(actual) diff --git a/lib/rspec/rails/matchers/have_rendered.rb b/lib/rspec/rails/matchers/have_rendered.rb index 27d6b22be2..7a0378f430 100644 --- a/lib/rspec/rails/matchers/have_rendered.rb +++ b/lib/rspec/rails/matchers/have_rendered.rb @@ -1,7 +1,6 @@ module RSpec::Rails::Matchers module RenderTemplate - class RenderTemplateMatcher - include RSpec::Matchers::BuiltIn::BaseMatcher + class RenderTemplateMatcher < RSpec::Matchers::BuiltIn::BaseMatcher def initialize(scope, expected, message=nil) @expected = Symbol === expected ? expected.to_s : expected diff --git a/lib/rspec/rails/matchers/redirect_to.rb b/lib/rspec/rails/matchers/redirect_to.rb index e488924a85..a0b09f5124 100644 --- a/lib/rspec/rails/matchers/redirect_to.rb +++ b/lib/rspec/rails/matchers/redirect_to.rb @@ -1,7 +1,6 @@ module RSpec::Rails::Matchers module RedirectTo - class RedirectTo - include RSpec::Matchers::BuiltIn::BaseMatcher + class RedirectTo < RSpec::Matchers::BuiltIn::BaseMatcher def initialize(scope, expected) @expected = expected diff --git a/lib/rspec/rails/matchers/routing_matchers.rb b/lib/rspec/rails/matchers/routing_matchers.rb index 7d4f1fcbbf..0330282af3 100644 --- a/lib/rspec/rails/matchers/routing_matchers.rb +++ b/lib/rspec/rails/matchers/routing_matchers.rb @@ -2,8 +2,7 @@ module RSpec::Rails::Matchers module RoutingMatchers extend RSpec::Matchers::DSL - class RouteToMatcher - include RSpec::Matchers::BuiltIn::BaseMatcher + class RouteToMatcher < RSpec::Matchers::BuiltIn::BaseMatcher def initialize(scope, *expected) @scope = scope @@ -58,8 +57,7 @@ def route_to(*expected) RouteToMatcher.new(self, *expected) end - class BeRoutableMatcher - include RSpec::Matchers::BuiltIn::BaseMatcher + class BeRoutableMatcher < RSpec::Matchers::BuiltIn::BaseMatcher def initialize(scope) @scope = scope From 603cf3dec2d649a7491db96b4274faac55ce927f Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Sat, 7 Jul 2012 15:36:41 -0500 Subject: [PATCH 41/42] revert all changes for #539 - not ready for release so backing out - changes are stored in engine-support branch --- Changelog.md | 3 --- lib/rspec/rails.rb | 23 ++++--------------- .../rails/example/controller_example_group.rb | 2 +- .../rails/example/mailer_example_group.rb | 2 +- .../rails/example/request_example_group.rb | 4 ++-- .../rails/example/routing_example_group.rb | 2 +- spec/rspec/rails/configuration_spec.rb | 14 ----------- .../example/request_example_group_spec.rb | 12 ---------- 8 files changed, 9 insertions(+), 53 deletions(-) diff --git a/Changelog.md b/Changelog.md index 943ec47bb6..8d6eaa3aa8 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,9 +7,6 @@ Enhancements specs run in random order by default. * rename `render_template` to `have_rendered` (and alias to `render_template` for backward compatibility) -* Specify a different application (e.g. an engine) instead of the Rails app: - `Rails.configuration.application = MyEngine` - default is `Rails.application` - (Dan Rasband @danrasban) Bug fixes diff --git a/lib/rspec/rails.rb b/lib/rspec/rails.rb index 64a87447d4..53047ed6a1 100644 --- a/lib/rspec/rails.rb +++ b/lib/rspec/rails.rb @@ -1,23 +1,8 @@ require 'rspec/core' -module RSpec - module Rails - def self.at_least_rails_3_1? - Gem::Version.new(::Rails.version) >= Gem::Version.new('3.1.0') - end - end -end - -RSpec.configure do |config| - config.backtrace_clean_patterns << /vendor\// - config.backtrace_clean_patterns << /lib\/rspec\/rails/ - config.add_setting :application, :default => ::Rails.application - - unless RSpec::Rails.at_least_rails_3_1? - def config.application=(*) - raise 'Setting the application is only supported on Rails 3.1 and above.' - end - end +RSpec::configure do |c| + c.backtrace_clean_patterns << /vendor\// + c.backtrace_clean_patterns << /lib\/rspec\/rails/ end require 'rspec/rails/extensions' @@ -29,4 +14,4 @@ def config.application=(*) require 'rspec/rails/module_inclusion' require 'rspec/rails/example' require 'rspec/rails/vendor/capybara' -require 'rspec/rails/vendor/webrat' \ No newline at end of file +require 'rspec/rails/vendor/webrat' diff --git a/lib/rspec/rails/example/controller_example_group.rb b/lib/rspec/rails/example/controller_example_group.rb index 92e76d5bca..eaaa028b55 100644 --- a/lib/rspec/rails/example/controller_example_group.rb +++ b/lib/rspec/rails/example/controller_example_group.rb @@ -120,7 +120,7 @@ def method_missing(method, *args, &block) metadata[:type] = :controller before do - @routes = RSpec.configuration.application.routes + @routes = ::Rails.application.routes ActionController::Base.allow_forgery_protection = false end end diff --git a/lib/rspec/rails/example/mailer_example_group.rb b/lib/rspec/rails/example/mailer_example_group.rb index 4ebb8bb959..03245c56bc 100644 --- a/lib/rspec/rails/example/mailer_example_group.rb +++ b/lib/rspec/rails/example/mailer_example_group.rb @@ -7,7 +7,7 @@ module MailerExampleGroup included do metadata[:type] = :mailer - include RSpec.configuration.application.routes.url_helpers + include ::Rails.application.routes.url_helpers options = ::Rails.configuration.action_mailer.default_url_options options.each { |key, value| default_url_options[key] = value } if options end diff --git a/lib/rspec/rails/example/request_example_group.rb b/lib/rspec/rails/example/request_example_group.rb index 602701d14b..80b9a57466 100644 --- a/lib/rspec/rails/example/request_example_group.rb +++ b/lib/rspec/rails/example/request_example_group.rb @@ -9,14 +9,14 @@ module RequestExampleGroup include ActionController::TemplateAssertions def app - RSpec.configuration.application + ::Rails.application end included do metadata[:type] = :request before do - @routes = RSpec.configuration.application.routes + @routes = ::Rails.application.routes end end end diff --git a/lib/rspec/rails/example/routing_example_group.rb b/lib/rspec/rails/example/routing_example_group.rb index 0e11ac6216..066b29709e 100644 --- a/lib/rspec/rails/example/routing_example_group.rb +++ b/lib/rspec/rails/example/routing_example_group.rb @@ -12,7 +12,7 @@ module RoutingExampleGroup metadata[:type] = :routing before do - @routes = RSpec.configuration.application.routes + @routes = ::Rails.application.routes end end diff --git a/spec/rspec/rails/configuration_spec.rb b/spec/rspec/rails/configuration_spec.rb index 804ad52480..258bef1b52 100644 --- a/spec/rspec/rails/configuration_spec.rb +++ b/spec/rspec/rails/configuration_spec.rb @@ -23,18 +23,4 @@ RSpec.configuration.render_views?.should be_true end end - - describe "#application" do - it "returns Rails.application by default" do - RSpec.configuration.application.should eq(::Rails.application) - end - end - - describe '#application=' do - context 'for Rails 3.0', :unless => RSpec::Rails.at_least_rails_3_1? do - it 'raises an error' do - expect { RSpec.configuration.application = ::Rails.application }.to raise_error - end - end - end end diff --git a/spec/rspec/rails/example/request_example_group_spec.rb b/spec/rspec/rails/example/request_example_group_spec.rb index d00d32bde2..fdd8918cec 100644 --- a/spec/rspec/rails/example/request_example_group_spec.rb +++ b/spec/rspec/rails/example/request_example_group_spec.rb @@ -13,17 +13,5 @@ module RSpec::Rails end group.metadata[:type].should eq(:request) end - - describe '#app' do - it 'returns the RSpec.configuration.application' do - group = RSpec::Core::ExampleGroup.describe do - include RequestExampleGroup - end - - example = group.new - - example.app.should eq(RSpec.configuration.application) - end - end end end From fb2f6f18d3376bc56be90741cdb6f9bd0556af09 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Sat, 7 Jul 2012 15:56:45 -0500 Subject: [PATCH 42/42] bump to 2.11.0 --- Changelog.md | 4 ++-- lib/rspec/rails/version.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index 8d6eaa3aa8..3133c5bf22 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,5 @@ -### dev -[full changelog](http://github.com/rspec/rspec-rails/compare/v2.10.1...master) +### 2.11.0 / 2012-07-07 +[full changelog](http://github.com/rspec/rspec-rails/compare/v2.10.1...v2.11.0) Enhancements diff --git a/lib/rspec/rails/version.rb b/lib/rspec/rails/version.rb index fdc572aec8..973ce1bd9e 100644 --- a/lib/rspec/rails/version.rb +++ b/lib/rspec/rails/version.rb @@ -1,7 +1,7 @@ module RSpec module Rails module Version - STRING = '2.10.1' + STRING = '2.11.0' end end end