2013年04月11日
■[Ruby]RSpecのbeforeはeachよりallが先に動く
はまったのでメモ。
beforeがどこに書かれているかに関わらず、eachよりもallの方が先に動くらしい。
spec_helper.rb
require "rspec" RSpec.configure do |config| config.before(:each) do puts "config before each" end end shared_context "sharecon" do before(:all) do puts "sharecon before all" end end
test_spec.rb
require "spec_helper" describe "test" do context "test" do include_context "sharecon" it { 1.should == 1 } end end
sharecon before all config before each . Finished in 0.00031 seconds 1 example, 0 failures
config.before(:each)の中でTimecop使ってfreezeしてたのに、
shared_contextの中で作ったDBのcreated_atがテストを動かした時間になってて、なんでかなーって調べてわかった。
2013年03月20日
■[Ruby]cucumber-railsでpendingがCIで失敗扱いになった話
メモ。
cucumber-railsを入れて、
rails generate cucumber:install
したときにできるconfig/cucumber.ymlが
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
%>
default: <%= std_opts %> features
wip: --tags @wip:3 --wip features
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
となって 単に bundle exec cucumber などとするとdefaultプロファイルが使われて、--strict も漏れなく付いてきてしまう。
https://github.com/cucumber/cucumber/wiki/Step-Definitions#pending-steps
--strictがついていると、pendingにしているfeatureがあった時点で、
テスト起動コマンド自体の返り値が0でない値*1が返ってきて、Jenkins氏はこのテストを失敗と見なしてしまう。
なので、ここは素直にCI用のプロファイルを作るのが正しいのではないでしょうか。
jenkins: --format pretty --format junit --out features/reports --tags ~@wip