Ruby on rails 3 测试在一起运行时失败,但单独通过

Ruby on rails 3 测试在一起运行时失败,但单独通过,ruby-on-rails-3,unit-testing,rspec,integration-testing,rspec-rails,Ruby On Rails 3,Unit Testing,Rspec,Integration Testing,Rspec Rails,我是RSPEC的新手,正在测试控制器。 有时,测试会像这样单独通过 rspec spec/controllers/controller_name_spec.rb 它过去了,但当我跑的时候:- rspec spec 测试失败,与先前通过的测试相同 原因可能是什么,是与rspec的可伸缩性有关还是与应用程序特定的问题有关。 正如我在集成测试中发现的一样。 轨道-v=>3.2.11 Ruby-v=>1.9.2p320 Rspec rails版本=>2.13.0 rspec版本=>2.13.0 例如

我是RSPEC的新手,正在测试控制器。 有时,测试会像这样单独通过

rspec spec/controllers/controller_name_spec.rb
它过去了,但当我跑的时候:-

rspec spec
测试失败,与先前通过的测试相同

原因可能是什么,是与rspec的可伸缩性有关还是与应用程序特定的问题有关。 正如我在集成测试中发现的一样。 轨道-v=>3.2.11 Ruby-v=>1.9.2p320 Rspec rails版本=>2.13.0 rspec版本=>2.13.0

例如:-

测试用例:-

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
响应错误消息:-

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)>'
仪表板控制器仪表板应该做些什么## 失败/错误:flash.now[:success]。不应为零 预期:不是零 得:零 #./spec/controllers/dashboard\u controller\u spec.rb:119:in'block(2层)in'
提前感谢

尝试添加
flash。对于与flash相关的每个测试,请在before块中清除


这可能会解决问题,也可能不会解决问题,但测试与flash相关的项目以避免flash对象被污染是至关重要的。

请测试代码和失败消息。@BillyChan编辑并添加了测试用例及其响应。我能想到的唯一原因是测试期间数据库未被清除。也许你可以检查这是否正确,然后安装database_cleaner gem。@BillyChan已经在“config.after(:each)do”中使用数据库清理器阻止它。虽然在调试时我知道了flash。现在[:success]出现了,但在运行“rspec spec”时错误仍然存在