ruby on rails - RSpec Helper Parameters Issue -


i'm trying test following code:

module applicationhelper   def current_book     book.find(params[:id])   end end 

using following test rspec:

rspec.describe applicationhelper, :type => :helper   describe "#current_book"     book_1 = create(:book)      params = {}     params[:id] = book_1.id      expect(helper.current_book).to eq(book_1)   end end 

but reason params[:id] parameter isn't being passed in properly. suggestions this?

you need stub params:

rspec.describe applicationhelper, type: :helper   describe "#current_book"     let(:first_book) { create(:book) }      before(:all) { helper.stub!(:params).and_return(id: 1) }      "returns book matching id"       expect(helper.current_book).to eq(first_book)     end   end end 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -