Giter VIP home page Giter VIP logo

minitest-vcr's Introduction

minitest-vcr

Project Gem Release
Gem name minitest-vcr
License MIT
Version Gem Version
Continuous Integration Build Status
Test Coverage Coverage Status
Grade Code Climate
Dependencies Dependency Status
Homepage http://mfpiccolo.github.io/minitest-vcr
Documentation http://rdoc.info/github/mfpiccolo/minitest-vcr/frames
Issues https://github.com/mfpiccolo/minitest-vcr/issues

Description

Allows VCR to automatically make cassetes with proper file paths using Minitest.

Examples

Two main steps:

  1. Install and require the gem
  2. Add MinitestVcr::Spec.configure! before your tests load

The setup below will create a directory structre that looks like this:

|-- app_name
|  |-- test/
|    |-- cassettes/
|      |-- Example_Spec/
|        |-- an_example_group/
|          |-- with_a_nested_example_group/
|          `-- uses_a_cassette_for_an_example_group.yml
|    `-- example_test.rb
|    `-- test_helper.rb

An example test_helper file: app_name/test/test_helper.rb

require "minitest/autorun"
require "minispec-metadata"
require "vcr"
require "minitest-vcr"
require "webmock"
require "mocha/setup"
require "faraday"

VCR.configure do |c|
  c.cassette_library_dir = 'test/cassettes'
  c.hook_into :webmock
end

MinitestVcr::Spec.configure!

An example test file: app_name/test/example_test.rb

require "test_helper"

describe Example::Spec do

  # Notice here symbols are treated as true values
  # You could also do vcr: true
  describe 'an example group', :vcr do
    describe 'with a nested example group' do
      before do
        conn = Faraday.new
        @response = conn.get 'http://example.com'
      end
      it 'uses a cassette for any examples' do
        @response.wont_equal nil
      end
    end
  end

  # setting config
  describe 'an example group', vcr: { record: :all } do
    describe 'with a nested example group' do
      before do
        conn = Faraday.new
        @response = conn.get 'http://example.com'
      end
      it 'uses a cassette for any examples' do
        @response.wont_equal nil
      end
    end
  end
end

Requirements

Installation

Add this line to your application's Gemfile:

gem "minitest-vcr"

And then execute:

$ bundle

Or install it yourself as:

$ gem install minitest-vcr

Donating

Support this project and others by mfpiccolo via gittip.

Copyright

Copyright (c) 2013 Mike Piccolo

See LICENSE.txt for details.

Contributing

  1. Fork it ( http://github.com/mfpiccolo/minitest-vcr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

githalytics.com alpha

minitest-vcr's People

Contributors

bitdeli-chef avatar jrochkind avatar mfpiccolo avatar phlipper avatar timruffles avatar vzvu3k6k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

minitest-vcr's Issues

inconsistent cassette naming when VCR options and nested describe

require "helper"

MinitestVcr::Spec.configure!

describe MinitestVcr::Spec, :vcr => {:tag => :some_tag, :match_requests_on => [:method, :uri, :body]} do
  before do
    conn = Faraday.new
    @response = conn.get 'http://example.com'
  end

  it "top level example" do

  end

  describe "nested describe" do
    it "example in nested describe" do

    end
  end

end

Will produce cassettes at:

test/cassettes/MinitestVcr/Spec/top_level_example.yml
test/cassettes/MinitestVcr_Spec/nested_describe/example_in_nested_describe.yml

The nested one is turning into a directory MinitestVcr_Spec instead of two dirs MinitestVcr/Spec.

I actually don't care which it is, the way minitest-vcr splits on module namespaces like that isn't important to me (although it doesn't really bother me either) -- but I need everything from the same example group to be in the same directory, not split between two as above. (So I can easily delete the directory when I want to regen cassettes, for instance).

There can be only one gem that calls #before or #after...

If any of other test helping library calls ::MiniTest::Spec.before or ::MiniTest::Spec.after, the last one called wins. That should not be the case. It makes for really hard to track down bugs,

  ::MiniTest::Spec.before :each, &run_before
  ::MiniTest::Spec.after :each, &run_after

Instead we should include a module with super for setup and teardown. All those methods do is redefine setup and teardown but they weren't designed to be used on the top level class.

It was supposed to be used in nested describe where each nesting is its own subclass.

support vcr 3.0

minitest-vcr is pinned to 2.x, would be cool to make sure it works well with vcr 3.x

Thanks! release?

Thanks for making this, it's just what I need!

I could use the features that were merged in from a PR 12 days ago -- are they in a release yet? It looks like 1.0.0 is the current release? If not, would it be possible to do a release with the latest?

It looks like there aren't any tags in the repo corresponding to releases -- if you use bundler's rake tasks to release a gem (rake release), then it'll automatically tag a v1.0.0 when you release 1.0.0, which makes it easier for developers to look at the repo and see what code corresponds to each release, to see if given code is in a given release.

uninitialized constant MiniTest (NameError)

Saw this gem listed as a Known Extension, decided to try it and got the following error

C:/Users/USER/opt/Ruby31-x64/lib/ruby/gems/3.1.0/gems/minispec-metadata-2.0.0/lib/core_extensions.rb:3:in `<top (required)>': uninitialized constant MiniTest (NameError)

if MiniTest.const_defined?(:Unit)
   ^^^^^^^^
Did you mean?  Minitest
        from C:/Users/USER/opt/Ruby31-x64/lib/ruby/gems/3.1.0/gems/minispec-metadata-2.0.0/lib/minispec-metadata.rb:2:in `require_relative'
        from C:/Users/USER/opt/Ruby31-x64/lib/ruby/gems/3.1.0/gems/minispec-metadata-2.0.0/lib/minispec-metadata.rb:2:in `<top (required)>'
        from C:/Users/USER/opt/Ruby31-x64/lib/ruby/gems/3.1.0/gems/minitest-vcr-1.4.0/lib/minitest-vcr/spec.rb:2:in `require'
        from C:/Users/USER/opt/Ruby31-x64/lib/ruby/gems/3.1.0/gems/minitest-vcr-1.4.0/lib/minitest-vcr/spec.rb:2:in `<top (required)>'
        from C:/Users/USER/opt/Ruby31-x64/lib/ruby/gems/3.1.0/gems/minitest-vcr-1.4.0/lib/minitest-vcr.rb:2:in `require'
        from C:/Users/USER/opt/Ruby31-x64/lib/ruby/gems/3.1.0/gems/minitest-vcr-1.4.0/lib/minitest-vcr.rb:2:in `<top (required)>'
        from C:/Users/USER/src/gitlab-report/spec/spec_helper.rb:13:in `require'
        from C:/Users/USER/src/gitlab-report/spec/spec_helper.rb:13:in `<top (required)>'
        from C:/Users/USER/src/gitlab-report/spec/gitlab_report/csv_report_spec.rb:3:in `require_relative'
        from C:/Users/USER/src/gitlab-report/spec/gitlab_report/csv_report_spec.rb:3:in `<top (required)>'
        from C:/Users/USER/opt/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:21:in `require'
        from C:/Users/USER/opt/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:21:in `block in <main>'
        from C:/Users/USER/opt/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in `select'
        from C:/Users/USER/opt/Ruby31-x64/lib/ruby/gems/3.1.0/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in `<main>'
rake aborted!

missing cassette name?

I'm having trouble where the cassette name is just ".yml" (no name before the .yml), which in addition to being inconvenient -- multiple it tests are winding up with that same request name, meaning the first one makes the cassette and subsequent ones complain about not finding the proper request in them.

I'm going to try and debug, and PR if possible, but I thought i'd check to see if you had any ideas or had run into this before. Thanks!

Adding 'minitest-vcr' to Gemfile brakes my test setup

After I've added 'minitest-vcr' to my gemfile it crashed my test setup with following error:

/Users/lun/.rvm/gems/[email protected]/gems/minitest-rails-1.0.1/lib/minitest/rails.rb:17:in `remove_method': method `describe' not defined in Class (NameError)
    from /Users/lun/.rvm/gems/[email protected]/gems/minitest-rails-1.0.1/lib/minitest/rails.rb:17:in `singleton class'
    from /Users/lun/.rvm/gems/[email protected]/gems/minitest-rails-1.0.1/lib/minitest/rails.rb:16:in `<class:TestCase>'
    from /Users/lun/.rvm/gems/[email protected]/gems/minitest-rails-1.0.1/lib/minitest/rails.rb:14:in `<top (required)>'
    from /Users/lun/.rvm/gems/[email protected]/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
    from /Users/lun/.rvm/gems/[email protected]/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `block in require'
    from /Users/lun/.rvm/gems/[email protected]/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:213:in `load_dependency'
    from /Users/lun/.rvm/gems/[email protected]/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in `require'
    from /Users/lun/client/worker.brokermint.com/test/test_helper.rb:4:in `<top (required)>'
    from /Users/lun/client/worker.brokermint.com/test/mailers/document_mailer_test.rb:1:in `require'
    from /Users/lun/client/worker.brokermint.com/test/mailers/document_mailer_test.rb:1:in `<top (required)>'
    from /Users/lun/.rvm/gems/[email protected]/gems/rake-10.3.2/lib/rake/rake_test_loader.rb:10:in `require'
    from /Users/lun/.rvm/gems/[email protected]/gems/rake-10.3.2/lib/rake/rake_test_loader.rb:10:in `block (2 levels) in <main>'
    from /Users/lun/.rvm/gems/[email protected]/gems/rake-10.3.2/lib/rake/rake_test_loader.rb:9:in `each'
    from /Users/lun/.rvm/gems/[email protected]/gems/rake-10.3.2/lib/rake/rake_test_loader.rb:9:in `block in <main>'
    from /Users/lun/.rvm/gems/[email protected]/gems/rake-10.3.2/lib/rake/rake_test_loader.rb:4:in `select'
    from /Users/lun/.rvm/gems/[email protected]/gems/rake-10.3.2/lib/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [ruby -I"lib:test" -I"/Users/lun/.rvm/gems/[email protected]/gems/rake-10.3.2/lib" "/Users/lun/.rvm/gems/[email protected]/gems/rake-10.3.2/lib/rake/rake_test_loader.rb" "test/{models,helpers,controllers,mailers,integration}/**/*_test.rb" ]
/Users/lun/.rvm/gems/[email protected]/gems/minitest-rails-1.0.1/lib/minitest/rails/tasks/minitest.rake:23:in `block (2 levels) in <top (required)>'
/Users/lun/.rvm/gems/[email protected]/gems/minitest-rails-1.0.1/lib/minitest/rails/tasks/minitest.rake:13:in `block in <top (required)>'
/Users/lun/.rvm/gems/[email protected]/bin/ruby_executable_hooks:15:in `eval'
/Users/lun/.rvm/gems/[email protected]/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => minitest:run
(See full trace by running task with --trace)

here is my test_helper.rb file
https://gist.github.com/skatkov/9e424d001840294006be

VCR cassette in 'before' block?

Is there any good way to have a VCR cassette in effect in a spec before block too, so I can do some setup http interactions in a before block, or should I just do it myself with VCR api?

Thanks for this gem!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.