概要
rspec config | custom settings
サンプル仕様
設定にdebugを追加。デフォルトをfalseにします。
実行時にはdebugモードをrandによってランダムに切り替えます。
hige_spec.rb
require 'spec_helper' require 'hige' RSpec.configuration.debug = true if rand > 0.5 describe Hige do context "hige1", :hige1 => "hige1_outer" do it "hige1", :hige1 => "hige1_inner" do puts "case hige1" if RSpec.configuration.debug expect("hige1_inner").to eq(example.metadata[:hige1]) end end it "hige2", :hige2 => "hige2" do puts "case hige2" if RSpec.configuration.debug expect("hige2").to eq(example.metadata[:hige2]) end end
spec_helper.rb
RSpec.configure do |config| config.treat_symbols_as_metadata_keys_with_true_values = true config.run_all_when_everything_filtered = true config.filter_run :focus config.add_setting :debug, :default => false end
実行結果(debugがtrueの場合)
$ rspec Run options: include {:focus=>true} All examples were filtered out; ignoring {:focus=>true} case hige2 .case hige1 . Finished in 0.001 seconds 2 examples, 0 failures
実行結果(debugがfalseの場合)
$ rspec Run options: include {:focus=>true} All examples were filtered out; ignoring {:focus=>true} .. Finished in 0.001 seconds 2 examples, 0 failures