Sha256: 1bb363a9264df85abd71cc879ef0ddc67ff7c285473a0872992520bfb43f9f6b

Contents?: true

Size: 1.24 KB

Versions: 26

Compression:

Stored size: 1.24 KB

Contents

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

      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
end  


Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
bento_search-2.0.0.rc1 test/support/test_with_cassette.rb
bento_search-1.7.0 test/support/test_with_cassette.rb
bento_search-1.6.1 test/support/test_with_cassette.rb
bento_search-1.7.0.beta.1 test/support/test_with_cassette.rb
bento_search-1.6.0 test/support/test_with_cassette.rb
bento_search-1.5.0 test/support/test_with_cassette.rb
bento_search-1.4.4 test/support/test_with_cassette.rb
bento_search-1.4.3 test/support/test_with_cassette.rb
bento_search-1.4.2 test/support/test_with_cassette.rb
bento_search-1.3.0 test/support/test_with_cassette.rb
bento_search-1.2.2 test/support/test_with_cassette.rb
bento_search-1.2.1 test/support/test_with_cassette.rb
bento_search-1.2.0 test/support/test_with_cassette.rb
bento_search-1.1.0 test/support/test_with_cassette.rb
bento_search-1.0.6 test/support/test_with_cassette.rb
bento_search-1.0.4 test/support/test_with_cassette.rb
bento_search-1.0.3 test/support/test_with_cassette.rb
bento_search-1.0.2 test/support/test_with_cassette.rb
bento_search-1.0.1 test/support/test_with_cassette.rb
bento_search-1.0.0 test/support/test_with_cassette.rb