Can anyone please let me know if it is possible to stub params[] values in controller spec, so that the controller accepts the stubbed values as actual params[] value from view.
for example, my view has a statement as
<%= form_tag("/expense_details/add_expense", :method=>"post") do %>
<%= text_field_tag(:eamt, nil, placeholder: "Expense Amount") %>
my controller has a statement as
expense_type= params[ :eamt ]
if !expense_type.nil?
session[:emsg]="filled"
else
session[:emsg]="empty"
end
my controller spec is as follows
it "successful save" do
my spec has condition as
post 'add_expense'
session[:emsg].should == "filled"
end
But my test is faling everytime with this below status
Failure/Error: session[:emsg].should == "filled"
expected: "filled"
got: "empty" (using ==)
can anyone please let me know how can i achieve this? Thanks in advance
In the RSpec controller spec, change the post line to:
post 'add_expense', eamt: 'stubbed_value'
The post method accepts a hash of options that will be considered parameters to the request. Docs from Rspec
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With