2011-06-29 12 views
4

と説明あなたはあなたが真実テストのみ1、それかTestUnitでRSpecの

ruby -Itest test/unit/user_test.rb -n test_the_truth 
のみテストを実行することができます例

require 'test_helper' 

class UserTest < ActiveSupport::TestCase 

    test "the truth" do 
    assert true 
    end 

    test "the truth 2" do 
    assert true 
    end 

end 

ために-nオプションを使用してファイルに

を一つのテストを起動することができます

ザウエット

1 tests, 1 assertions, 0 failures, 0 errors, 0 skip 

どのようにrspecでそれができますか?

コマンドは、あなたがあなたのスペックのソースが含まれていなかったので、それは問題がどこにあるか言うのは難しいのですが、一般的に、あなた実行する-eオプションを使用することができます

rspec spec/models/user_spec.rb -e "User the truth" 

答えて

7

を動作しないように見えます単一の例。このスペックを考える:

# spec/models/user_spec.rb 
require 'spec_helper' 
describe User do 

    it "is true" do 
    true.should be_true 
    end 

    describe "validation" do 
    it "is also true" do 
     true.should be_true 
    end 
    end 

end 

このコマンドライン:

rspec spec/models/user_spec.rb -e "User is true" 

は、この出力演出します:

Run filtered including {:full_description=>/(?-mix:User\ is\ true)/} 
. 

Finished in 0.2088 seconds 
1 example, 0 failures 

をそして、あなたは他の例を起動したい場合、一つは検証の中にネストあなたはこれを使うでしょう:

rspec spec/models/user_spec.rb -e "User validation is also true" 

または検証グループ内のすべての例を実行するには:

rspec spec/models/user_spec.rb -e "User validation" 
+0

私はもう一度試してみて、それが動作します!私は何が起こったのか本当に理解していない....しかし、それは私がそれに戻って行ったので、あなたの答えに感謝! –

2

またラインが実行したいテストケースである選択することができます。

rspec spec/models/user_spec.rb:8 

テストケースのスコープ内に任意の行を渡すと、このテストケースだけが実行されます。これを使用して、テスト内で全体的なコンテキストを実行することもできます。

1

少なくともRSPECの2.11.1には、次のオプションをすべて使用することができます。

**フィルタリング/タグを**

In addition to the following options for selecting specific files, groups, 
or examples, you can select a single example by appending the line number to 
the filename: 

    rspec path/to/a_spec.rb:37 

-P, --pattern PATTERN   Load files matching pattern (default: "spec/**/*_spec.rb"). 
-e, --example STRING    Run examples whose full nested names include STRING (may be 
            used more than once) 
-l, --line_number LINE   Specify line number of an example or group (may be 
            used more than once). 
-t, --tag TAG[:VALUE]   Run examples with the specified tag, or exclude examples 
           by adding ~ before the tag. 
            - e.g. ~slow 
            - TAG is always converted to a symbol 
関連する問題