Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RSpec: undefined method `allow' for #<RSpec::Core::ExampleGroup::Nested

I'm writing a view spec in RSpec 2.12.2. The error I'm getting is undefined method: allow. I have used something similar in later versions of RSpec. Is allow not present in 2.12.2? Is there another way to stub a method call in this version?

require 'spec_helper'

describe "user_achievements/index.html.haml" do
  let(:application) { double }
  let(:user) { double }

  before do
    allow(view).to receive_message_chain(:user, :registered?).and_return(true)

    render
  end

  it "includes a table for user achievements" do
    expect(rendered).to have_css(".data-table")
  end
end
like image 801
rainslg Avatar asked Feb 27 '26 21:02

rainslg


1 Answers

Allow wasn't introduced until 2.14. You can use obj.stub and stub_chain

# specify a return value
obj.stub(:message) { :value }
obj.stub(:message => :value)
obj.stub(:message).and_return(:value)

subject.stub_chain(:one, :two, :three).and_return(:four)
like image 197
osman Avatar answered Mar 02 '26 15:03

osman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!