Sha256: ca9c13d8876e418d913d9d98f9fbbb8c5570279c4a024d56660158cc5e13e9a5
Contents?: true
Size: 1.35 KB
Versions: 4
Compression:
Stored size: 1.35 KB
Contents
# Copied from jrochkind's bento search. # TODO: Investigate a DRYer way to copy from jrochkind's bento search. module TestWithCassette def test_with_cassette(name, group = nil, vcr_options ={}, &block) # cribbed from Rails and modified for VCR # https://github.com/rails/rails/blob/b451de0d6de4df6bc66b274cec73b919f823d5ae/activesupport/lib/active_support/testing/declarative.rb#L25 test_name_safe = name.gsub(/\s+/,'_') test_method_name = "test_#{test_name_safe}".to_sym raise "#{test_method_name} is already defined in #{self}" if methods.include?(test_method_name) cassette_name = vcr_options.delete(:cassette) unless cassette_name # calculate default cassette name from test name cassette_name = test_name_safe # put in group subdir if group cassette_name = "#{group}/#{cassette_name}" if group end # default tag with groupname, can be over-ridden. vcr_options = {:tag => group}.merge(vcr_options) if group # vcr_options.merge!(:serialize_with => :json) if block_given? define_method(test_method_name) do VCR.use_cassette(cassette_name , vcr_options) do instance_eval &block end end else define_method(test_method_name) do flunk "No implementation provided for #{name}" end end end alias_method :test, :test_with_cassette end
Version data entries
4 entries across 4 versions & 1 rubygems