私は以下を介して私が探していたものをなんとか手に入れることができました:
# Exclude :performance tagged specs by default
config.filter_run_excluding :performance => true
# When we're running a performance test load the test fixures:
config.before(:all, :performance => true) do
# load performance fixtures
require 'active_record/fixtures'
ActiveRecord::Fixtures.reset_cache
ActiveRecord::Fixtures.create_fixtures('spec/perf_fixtures', File.basename("products.yml", '.*'))
ActiveRecord::Fixtures.create_fixtures('spec/perf_fixtures', File.basename("ingredients.yml", '.*'))
end
# define an rspec helper for takes_less_than
require 'benchmark'
RSpec::Matchers.define :take_less_than do |n|
chain :seconds do; end
match do |block|
@elapsed = Benchmark.realtime do
block.call
end
@elapsed <= n
end
end
# example of a performance test
describe Api::ProductsController, "API Products controller", :performance do
it "should fetch all the products reasonably quickly" do
expect do
get :index, :format => :json
end.to take_less_than(60).seconds
end
end
しかし、私は、これがパフォーマンステストの最良のアイデアではないというMarnenの指摘に同意する傾向があります。