Comments (6)
Hey @jrochkind this does look right. A few thoughts:
-
Why do you have those library requires in your test_helper file? If those are in your
test
group of yourGemfile
then the requires are moot? Just a note. Maybe you are just showing me which libs you use tho? -
I have a few integration Rails projects on my GitHub profile. Here is one for Rails 4.1 and latest MTSR. https://github.com/metaskills/mtsr_integration_v41
-
I added a demo integration test and it worked great. metaskills/mtsr_integration_v41@980e8af
Given this, I suspect you have something wonky in your setup or the gems you are using. I would give minitest-vcr a look over.
from minitest-spec-rails.
I just looked over their source. FWIW, I use VCR a lot and just write a few of my own helpers. This gem does not add much. It also uses MiniTest meta data (https://github.com/mfpiccolo/minitest-vcr/blob/master/minitest-vcr.gemspec#L23) which I'm not a terrible fan of. Not sure how strong that interface is in MiniTest and even what happens to Rails apps which the Spec::DSL is inserted into.
from minitest-spec-rails.
Thanks. I am in the habit of require'ing gems used in tests in my test_helper, is there any reason it would cause a problem? I forget if things didn't work until I required them.
I will work on reducing to minimal reproducible case to see if any of the extra gems were causing the problem or what. Thanks for the demo working integration test to compare with.
Can you share the code for the 'few of your own helpers' you use with VCR, minitest/spec, and Rails? What I like from minitest-vcr is the ability to attach a few tokens to a describe
context, and thereby have every example run in a use_cassette
with the name/path of the cassette derived from the (possibly nested) description/examples. VCR does this for Rspec out of the box, as the VCR developer (who I think may also currently be the rspec developer?) believes this is the most convenient way to use VCR in spec syntax, and I agree with him. Curious if your helpers do this, or something else, either way I'm curious to see them.
from minitest-spec-rails.
Something like this:
module TestHelper
module ServiceHelpers
extend ActiveSupport::Concern
included do
VCR.configure do |c|
c.cassette_library_dir = 'test/vcr_cassettes'
c.hook_into :webmock
c.ignore_localhost = true
end
extend VCRClassHelpers
end
module VCRClassHelpers
def with_cassette(*args, &block)
cassette_options = args.last.is_a?(Hash) ? args.pop : {}
cassette_name = args.first || name
describe "with cassette #{cassette_name}" do
use_vcr_cassette cassette_name, cassette_options
instance_eval(&block)
end
end
def use_cassette(name, options={})
options = default_cassette_options.merge(options)
VCR.use_cassette(name, options) { yield }
end
def use_vcr_cassette(cassette_name, cassette_options={})
before do
unless self.class.allow_http_connections?
VCR.insert_cassette cassette_name, default_cassette_options.merge(cassette_options)
end
end
after do
unless self.class.allow_http_connections?
VCR.eject_cassette
end
end
end
def allow_http_connections?
ENV['ALLOW_HTTP_CONNECTIONS'] && ENV['ALLOW_HTTP_CONNECTIONS'] == 'true'
end
def default_cassette_options
{ serialize_with: :syck, allow_playback_repeats: true }
end
end
private
# VCR
def use_cassette(name, options={})
self.class.use_cassette(name, options) { yield }
end
def eject_cassette
VCR.eject_cassette
end
def default_cassette_options
self.class.default_cassette_options
end
# General
def enable_net_connections
WebMock.allow_net_connect!
end
def disable_net_connections
WebMock.disable_net_connect! allow_localhost: true
end
end
end
from minitest-spec-rails.
The serialize_with: :syck
option is really nice too. Allows your cassette data to be human readable if needed.
from minitest-spec-rails.
Can you include an example of how you use that helper method? The with_cassette
method is what you use in your specs, and basically serves as a substitute for the describe
, it creates a describe, such that all the examples in it will be wrapped in cassettes? With every example in the describe sharing the same cassette, or each having a different?
Honestly, figuring out how to do this stuff is non-trivial for those not as familiar with minitest/spec and VCR as you. Personally I do like the approach minitest-vcr takes of letting metadata on describe or examples trigger the VCR cassette -- this is the same approach vcr/rspec integration takes, although with minitest it does require an extra gem since minitest/spec doesn't support metadata out of the box.
But if you think you have a better way to do it, I'd encourage you to consider packaging it up in a gem with documentation, as I think many users are having more trouble with this than you might think.
from minitest-spec-rails.
Related Issues (20)
- Initialization autoloaded the constants ActionText::ContentHelper using Rails 6.0.3.1 HOT 1
- stack level too deep HOT 2
- Issue testing Helpers after upgrading to Rails 6.1
- Cheetsheet link dead HOT 2
- Deprecation warning when used with flipper/prawn-rails HOT 2
- Rspec-rails and Minitest-spec-rails HOT 3
- Cheat sheet missing? HOT 1
- Using string instead of constant for describe argument causes data leakage
- Interview partners for research about communication in GitHub projects wanted
- Use new Minitest constant over MiniTest HOT 1
- Breaks order setting for Rails and Minitest HOT 7
- rails 5 test outputs wrong location of test case HOT 17
- Shouldn't depend on rails gem HOT 3
- When test methods are mixed with describe blocks, they get run multiple times sometimes. HOT 3
- more information HOT 4
- Rails 3.2: empty test is ran after every rake command HOT 6
- Rails 5 support? HOT 1
- Pararallel testing HOT 9
- Rails 6 errors current_server': DRb::DRbServerNotFound (DRb::DRbConnError) HOT 6
- Unable to run tests locally
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minitest-spec-rails.