Giter VIP home page Giter VIP logo

Comments (14)

jrochkind avatar jrochkind commented on September 16, 2024

Okay, trying to add some failing tests to figure out what's triggering the bug in my case, I notice that if your describe starts with a capital letter, it does something slightly different than expected by existing tests:

describe 'OneWord', :vcr do
      it 'uses a cassette for any examples' do
        (VCR.current_cassette.name.split('/')).must_equal([
          'MinitestVcr::Spec',
          'OneWord',
          'uses a cassette for any examples'
        ])
      end
  end

  1) Failure:
MinitestVcr::Spec::OneWord::vcr#test_0001_uses a cassette for any examples [/Users/jrochkind/code/minitest-vcr/test/minitest-vcr/spec_test.rb:27]:
--- expected
+++ actual
@@ -1 +1 @@
-["MinitestVcr::Spec", "OneWord", "uses a cassette for any examples"]
+["MinitestVcr::Spec::OneWord", "uses a cassette for any examples"]

Is it expected that it jams the one word onto the end of the first component. It seems to only happen when it begins with a capital letter. Not sure if this is related to my bug or not.

from minitest-vcr.

jrochkind avatar jrochkind commented on September 16, 2024

Bah, that's probably not it.

Something really weird is going on, which looks possibly somehow related to using VCR's filter_sensitive_data functionality, although that doesn't make a lot of sense.

I'm also in some cases, even without filter_sensitive_data, getting crazy extra-long path names for yml cassettes, that include the names of other unrelated tests in them.

Can't quite reproduce in minitest test spec; could it somehow be related to using WebMock, as I am?

I guess I'll go off into the debugger to try and figure it out.

from minitest-vcr.

jrochkind avatar jrochkind commented on September 16, 2024

In my own app, I have now managed to isolate and reproduce the case where VCR.current_cassette.name is nil, and thus the cassette ends up being called just ".yml".

I haven't managed to reproduce it yet in minitest-vcr's own tests; maybe my own unique dependencies? Trying to figure it out.

from minitest-vcr.

jrochkind avatar jrochkind commented on September 16, 2024

Okay! It's when I try to pass a :tag to VCR. Drop this file into minitest-vcr master, it demonstrates:

require 'helper'

MinitestVcr::Spec.configure!


describe "with tag metadata", :vcr => {:tag => :bd_finditem} do

  before do
    conn = Faraday.new
    @response = conn.get 'http://example.com'
  end

  it "uses appropraite cassette name" do

        assert ! VCR.current_cassette.nil?, "No current cassette"

        assert ! VCR.current_cassette.name.nil?, "No current cassette name"


        if VCR.current_cassette.name
          (VCR.current_cassette.name.split('/')).must_equal([
            'with tag metadata',
            'uses appropraite cassette name'
          ])
        end
  end

end

I'll see if I can debug it and PR it, but any advice/help welcome!

from minitest-vcr.

mfpiccolo avatar mfpiccolo commented on September 16, 2024

Good stuff Jonathan! Thanks for the debugging. I will give this a look soon.

from minitest-vcr.

jrochkind avatar jrochkind commented on September 16, 2024

Okay!

So in typical cases like it "example", :vcr, the example.class.name that gets passed to minitest-vcr here looks like "name of example::vcr".

However, if you pass a tag (or maybe any extra arguments at all?) to vcr, like:

 it "example", :vcr => {:tag => :foo}

Then for some reason the example.class.name is missing the suffix, and just looks like "name of example".

The scan regexp then doesn't scan it properly, and ends up with an empty class_name.

Not entirely sure the right way to fix it. I can make the scan regex more complicated, but I'm not sure I understand what's going on.

I also wonder if a self-check should be done there, and raise right there if the class_name extracted is nil or empty string, rather than passing it on to create a casette name like just .yml.

There's other weird stuff going on in my case too, but I'm hoping once we fix this one, it'll fix the others too!

from minitest-vcr.

jrochkind avatar jrochkind commented on September 16, 2024

or wiat, maybe not. i'm so confused. i'm hoping my example reproduces for you, and you can help!

from minitest-vcr.

jrochkind avatar jrochkind commented on September 16, 2024

yeah, can't manage to fix this in a way that doesn't break other things; I don't entirely understand what's going on or what the intention of your code is, def need your help! In the meantime, I'll avoid using :tag, but I kind of need it!

from minitest-vcr.

mfpiccolo avatar mfpiccolo commented on September 16, 2024

I am busy for the next few hours but hopefully I will be able to jump in figure out this tag thing later today. I do not use tags in requests so it might help to tell me an example use-case for tagging tests.

from minitest-vcr.

jrochkind avatar jrochkind commented on September 16, 2024

cool! I won't return to it again until Monday probably.

It's not just tags, it's actually any metadata you pass to VCR. This also breaks it:

it "something", :vcr => { :match_requests_on => [:body]  }

And while I can do without tags for now, I can't do without that, I need it for my tests to work.

from minitest-vcr.

jrochkind avatar jrochkind commented on September 16, 2024

These are options you pass to VCR -- you aren't tagging tests exactly you are tagging VCR cassettes, actually. Or passing other options to VCR.

The use case for passing a :tag argument to VCR is so you can apply other VCR hooks to only VCR cassettes with certain tags: https://www.relishapp.com/vcr/vcr/v/1-6-0/docs/configuration/hooks

I use it for applying certain VCR filter_sensitive_data operations to only certain requests.

But the bug is not just triggered by the VCR :tag option, but by any option you pass to VCR at all. For instance in my above example, :match_requests_on => [:body]. I think the use case for that, and various other VCR options, is pretty clear, but I can explain or point to the parts of VCR documentation that do, if you need.

from minitest-vcr.

mfpiccolo avatar mfpiccolo commented on September 16, 2024

Thanks for looking into this. The issue was the regex was scanning expecting a class as the first describe (i.e. Some::Class). It now works with a string description. Closed by #14

from minitest-vcr.

mfpiccolo avatar mfpiccolo commented on September 16, 2024

@jrochkind Thanks for the rake release BTW. v1.0.1 is cut.

from minitest-vcr.

jrochkind avatar jrochkind commented on September 16, 2024

Thanks very much!

from minitest-vcr.

Related Issues (9)

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.