Reputation: 1936
I am new to RSPEC and am testing the controllers. Sometimes it happens that the test passes alone like
rspec spec/controllers/controller_name_spec.rb
it passes but when I run :-
rspec spec
the test fails, same test that passed earlier.
What can be the reason, is it related to scalability of rspec or an application specific issue. As I found same issue with integration tests also. Rails -v => 3.2.11 Ruby -v => 1.9.2p320 Rspec-rails version => 2.13.0 rspec version => 2.13.0
eg:-
Test case :-
it "should do ##something##" do
plans=Plan.pluck(:id)
plans.delete(@user.subscription.plan.id)
@user.subscription.stripe_customer_token= "cus_1l9m6CicQEXZJ0"
@user.save
get 'apply_change_account', {:subscription=>{:plan_id=>plans.sample}}
flash.now[:success].should_not be_nil
response.should redirect_to dashboard_manage_accounts_path
end
Response error message :-
1) DashboardController Dashboard should do ##something##
Failure/Error: flash.now[:success].should_not be_nil
expected: not nil
got: nil
# ./spec/controllers/dashboard_controller_spec.rb:119:in `block (2 levels) in <top (required)>'
Thanks in advance
Upvotes: 0
Views: 686
Reputation: 24815
Try add flash.clear
in before block for every test related to flash.
This may or may not solve the problem, but it's essential to test flash related item to avoid flash object been polluted.
Upvotes: 1