[rspec-users] shared examples with a block for expects?

Patrick J. Collins patrick at collinatorstudios.com
Thu May 24 00:12:54 UTC 2012


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



More information about the rspec-users mailing list