루비 rake rspec
Rails에서 simplecov 이용해서 coverage 추가할 때 샘플 코드
- rake_require 호출하는 부분을 전체를 커버하는 before에서 한 번만 호출해야 coverage 정상적으로 적용됨
- rake_require를 여러번 호출하거나 scope 다르게 해서 호출할 경우 기존 coverage 정보 갱신되서 마지막으로 적용된 coverage만 표시됨
test.rake
require 'wheel/task_context'
namespace :foo do
desc "bake some bars"
task bake_a_problematic_bar: :environment do
puts '*' * 60
puts ' Step back: baking in action!'
puts '*' * 60
puts '*' * 60
puts ' All done. Thank you for your patience.'
puts '*' * 60
end
end
test_rake_spec
require 'support/shared_context'
require 'rails_helper'
require 'rake'
describe 'foo namespace rake task' do
describe 'foo:bake_a_problematic_bar' do
before do
# load File.expand_path("../../../lib/tasks/test.rake", __FILE__)
# Rake::Task.define_task(:environment)
Rake.application.rake_require "tasks/test"
Rake::Task.define_task(:environment)
end
it "should bake a bar" do
# Bar.any_instance.should_receive :bake
Rake::Task["foo:bake_a_problematic_bar"].invoke
end
it "should bake a bar again" do
# Bar.any_instance.should_receive :bake
Rake::Task["foo:bake_a_problematic_bar"].invoke
end
end
end
댓글
댓글 쓰기