1

ファイル内で単一の仕様を実行するには、さまざまな方法があることを知っています。つまり、仕様がタグ付けされていない限り、これは魅力のように機能します (つまり、非常に遅いため..)

rspec spec/models/event_spec.rb:311

これにより、遅いとタグ付けされたすべての仕様が実行されます...

rspec -t slow spec/models/event_spec.rb

...しかし、完了するまでに約 2 年かかります。

低速スペックの実行を制限しようとする次の試みはすべて、指定されたファイルからタグ付けされていないすべてのスペックを実行することになります。

rspec -t slow -e "A describe block tagged as slow" spec/models/event_spec.rb
rspec -e "A describe block tagged as slow" spec/models/event_spec.rb
rspec -t slow spec/models/event_spec.rb:378 #the line number of the describe block
rspec spec/models/event_spec.rb:378 #the line number of the describe block
rspec -e "A single slow spec" -t slow spec/models/event_spec.rb
rspec -t slow -e "A single slow spec" -t slow spec/models/event_spec.rb
rspec -t slow spec/models/event_spec.rb:466 #a line number of a single slow spec
rspec spec/models/event_spec.rb:466 #a line number of a single slow spec
#It seems the order of the file/path and the options makes no difference..
rspec spec/models/event_spec.rb -t slow -e "A describe block tagged as slow"
rspec spec/models/event_spec.rb -e "A describe block tagged as slow"
rspec spec/models/event_spec.rb:378 -t slow #the line number of the describe block
rspec spec/models/event_spec.rb -e "A single slow spec" -t slow
rspec spec/models/event_spec.rb -t slow -e "A single slow spec"
rspec spec/models/event_spec.rb#466 -t slow #a line number of a single slow spec

これは不可能ですか、それとも何が間違っていますか?

PS Rspec バージョン 2.10.1

アップデート

spec_helper では、Rspec がデフォルトで遅いテストを実行しないように (明らかに) 構成されており、すべてがフィルター処理された場合はすべてのテストを実行するように構成されていることは言及しませんでした。(TBH、これがデフォルトの動作だと思っていたので、最初は言及しませんでした)

RSpec.configure do |config|
  config.mock_with(:rspec)
  config.expect_with(:rspec)
  config.filter_run_excluding(:slow => true)
  config.run_all_when_everything_filtered = true
end

そして、これは動作をテストするのに十分なはずです:

# -*- encoding : utf-8 -*-
require 'spec_helper'

describe 'Demonstrating tagging issue' do
  describe "some tests that take a very long time to run", slow: true do
    it "slow test 1" do
      puts "it should be slow"
    end
    it "shlow test 2" do
      puts "it should be slow too"
    end
  end
  it "normal test" do
    puts "it should be fast"
  end
end

したがって、実行する正確なテストを行番号またはサンプル名で指定しようとすると、遅い仕様を無視するという設定済みのデフォルトの動作を強制的に変更しようとするすべての努力が無視されるようです..したがって、すべてがフィルタリングされ、その後、すべてを実行します。

更新 2

私が達成しようとしていることをさらに特定するために。複数の例のタグが遅いファイルがあるファイルがあります。これらのタグには触れたくないので、これらの遅い例の 1 つを実行したいと思います。私のspec_helper.rbからこの設定をコメントアウトすれば、これは簡単なことです

config.filter_run_excluding(:slow => true)

次に、行番号の指定、-e cmd 行オプション、使用したいフォーカス タグのいずれかの方法が機能します。ただし、構成をいじる必要なく、それを達成できると期待していました。今のところ、これは実際には不可能である可能性が最も高いと確信しています..

4

1 に答える 1

0

私はあなたの例でいくつかの調整を行いました、そしてそれはあなたが望むように働くことを願っています。

spec/something_spec.rb:

# -*- encoding : utf-8 -*-
require 'spec_helper'

describe 'Demonstrating tagging issue' do
  describe "run differently slow" do
    it "is slow", slow: true do
      true.should be_true
    end

    it "is not so fast" do
      true.should be_true
    end

    it "normal test" do
      true.should be_true
    end
  end
end

ターミナル:

╭─@krasimir.local /private/tmp/rtest ‹ruby-1.9.2@test› 
╰─ rspec -f d --tag true  
Run options: include {:focus=>true, :true=>true}

All examples were filtered out; ignoring {:focus=>true, :true=>true}

Demonstrating tagging issue
  run differently slow
    is slow
    is not so fast
    normal test

Finished in 0.00527 seconds
3 examples, 0 failures

Randomized with seed 57868

╭─@krasimir.local /private/tmp/rtest ‹ruby-1.9.2@test› 
╰─ rspec -f d --tag slow
Run options: include {:focus=>true, :slow=>true}

Demonstrating tagging issue
  run differently slow
    is slow

Finished in 0.00772 seconds
1 example, 0 failures

私が使用した:

  • Ruby:ruby 1.9.2p320(2012-04-20リビジョン35421)[x86_64-darwin12.0.0]
  • RSpec:2.11.1
于 2012-08-09T21:41:05.490 に答える