Skip to content

Commit

Permalink
ControllerExampleGroup uses controller as the implicit subject by def…
Browse files Browse the repository at this point in the history
…ault

Restores functionality from RSpec 1.X.  Hat tip to jferris for the original
patch. (Closes rspec#223)
  • Loading branch information
tessro committed Sep 30, 2010
1 parent 6caa515 commit 4d63ccb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rspec/rails/example/controller_example_group.rb
Expand Up @@ -169,6 +169,7 @@ module InstanceMethods
@routes = ::Rails.application.routes
ActionController::Base.allow_forgery_protection = false
end
subject { controller }
end

RSpec.configure &include_self_when_dir_matches('spec','controllers')
Expand Down
27 changes: 27 additions & 0 deletions spec/rspec/rails/example/controller_example_group_spec.rb
Expand Up @@ -18,5 +18,32 @@ module RSpec::Rails
end
group.metadata[:type].should eq(:controller)
end

it "should use the controller as the implicit subject" do
group = RSpec::Core::ExampleGroup.describe do
include ControllerExampleGroup
end

example = group.new

controller = double('controller')
example.stub(:controller => controller)

example.subject.should == controller
end

describe "with a specified subject" do
before do
@group = RSpec::Core::ExampleGroup.describe do
include ControllerExampleGroup
subject { 'specified' }
end
end

it "should use the specified subject instead of the controller" do
example = @group.new
example.subject.should == 'specified'
end
end
end
end

0 comments on commit 4d63ccb

Please sign in to comment.