【问题标题】:Rails Rspec - Run only single testRails Rspec - 仅运行单个测试
【发布时间】:2016-11-07 07:53:24
【问题描述】:

我正在学习 RSpec。我只想在单个文件上运行 rspec。我通过

cd to/my/project

和

rspec ./spec/parent/child/spec.rb

但是在我给出这个命令之后

rspec --order rand:seed

我的 rspec 从一开始就运行所有测试。如何撤消此命令?

【问题讨论】:

    标签: ruby-on-rails unit-testing rspec rspec-rails


    【解决方案1】:

    试试这个来运行一个测试:

    rspec ./spec/parent/child/spec.rb:line_number_of_your_test
    

    如果您的it 块是多行块,line_number_of_your_test 可以是跨越测试的任何数字。

    更新:删除了“rand:seed”部分。

    【讨论】:

    【解决方案2】:

    你只需要运行

    rspec your_file.rb:number_of_line
    

    所以如果你的文件名是login.rb 并且看起来像

    1 describe "test something" do
    2  it "signup" do
    3   ...
    4  end
    5  it "signin" do
    6   ...
    7  end
    8 end
    

    而你只想运行"signin" 测试,你需要运行

    rspec login.rb:5
    

    【讨论】:

      猜你喜欢
      • 2012-11-28
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      • 2010-12-03
      • 1970-01-01
      • 2019-02-21
      • 2014-05-18
      相关资源
      最近更新 更多