Patrick J. Collins
2012-May-24 00:12 UTC
[rspec-users] shared examples with a block for expects?
Hi,
Basically I want to do something like this:
describe FancyThingsController do
def do_new
get :new
end
def do_create
post :create, :fancy_thing => { :some => "params" }
end
shared_examples "an access controlled action" do |expectation|
it "denies access" do
expect(&expectation).to raise_error(CanCan::AccessDenied)
end
end
describe "#new" do
it_behaves_like "an access controlled action", proc { do_new }
end
describe "#create" do
it_behaves_like "an access controlled action", proc { do_create }
end
end
but I get: "expected CanCan::AccessDenied, got #<NameError: undefined
local variable or method `do_create'' for
RSpec::Core::ExampleGroup::Nested_1::Nested_2:Class>"
Just curious, how can I do this?
Patrick J. Collins
http://collinatorstudios.com
On May 23, 2012, at 6:12 PM, Patrick J. Collins wrote:> Hi, > > Basically I want to do something like this: > > describe FancyThingsController do > > def do_new > get :new > end > > def do_create > post :create, :fancy_thing => { :some => "params" } > end > > shared_examples "an access controlled action" do |expectation| > it "denies access" do > expect(&expectation).to raise_error(CanCan::AccessDenied) > end > end > > describe "#new" do > it_behaves_like "an access controlled action", proc { do_new } > end > > describe "#create" do > it_behaves_like "an access controlled action", proc { do_create } > end >Just use a Proc: describe ''#new'' do it_behaves_like ''an access controlled action'', -> { get :new } end> end > > but I get: "expected CanCan::AccessDenied, got #<NameError: undefined > local variable or method `do_create'' for > RSpec::Core::ExampleGroup::Nested_1::Nested_2:Class>" > > Just curious, how can I do this? > > Patrick J. Collins > http://collinatorstudios.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users