Skip to content

Commit

Permalink
Merge 2b87569 into c485494
Browse files Browse the repository at this point in the history
  • Loading branch information
tarebyte committed Oct 13, 2018
2 parents c485494 + 2b87569 commit 67bcc6c
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 104 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
@@ -1,7 +1,8 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1.3
- 2.3
- 2.4
- 2.5

script: bundle exec rake
notifications:
email: false
10 changes: 9 additions & 1 deletion Gemfile
@@ -1,7 +1,15 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gem 'coveralls', require: false

group :development, :test do
gem 'faraday', '~> 0.15.3'
gem 'mocha', '~> 1.7'
gem 'webmock', '~> 3.4', '>= 3.4.2'
gem 'yard', '~> 0.9.16', require: false
end

# Specify your gem's dependencies in minitest-vcr.gemspec
gemspec

9 changes: 4 additions & 5 deletions README.md
Expand Up @@ -4,11 +4,10 @@ minitest-vcr
|------------------------ | ----------------- |
| Gem name | minitest-vcr |
| License | [MIT](LICENSE.txt) |
| Version | [![Gem Version](https://badge.fury.io/rb/minitest-vcr.png)](http://badge.fury.io/rb/minitest-vcr) |
| Continuous Integration | [![Build Status](https://travis-ci.org/mfpiccolo/minitest-vcr.png?branch=master)](https://travis-ci.org/mfpiccolo/minitest-vcr)
| Test Coverage | [![Coverage Status](https://coveralls.io/repos/mfpiccolo/minitest-vcr/badge.png?branch=master)](https://coveralls.io/r/mfpiccolo/minitest-vcr?branch=coveralls)
| Grade | [![Code Climate](https://codeclimate.com/github/mfpiccolo/minitest-vcr.png)](https://codeclimate.com/github/mfpiccolo/minitest-vcr)
| Dependencies | [![Dependency Status](https://gemnasium.com/mfpiccolo/minitest-vcr.png)](https://gemnasium.com/mfpiccolo/minitest-vcr)
| Version | [![Gem Version](https://badge.fury.io/rb/minitest-vcr.svg)](https://badge.fury.io/rb/minitest-vcr) |
| Continuous Integration | [![Build Status](https://travis-ci.org/mfpiccolo/minitest-vcr.svg?branch=master)](https://travis-ci.org/mfpiccolo/minitest-vcr)
| Test Coverage | [![Coverage Status](https://coveralls.io/repos/github/mfpiccolo/minitest-vcr/badge.svg?branch=master)](https://coveralls.io/github/mfpiccolo/minitest-vcr?branch=master)
| Grade | [![Maintainability](https://api.codeclimate.com/v1/badges/9627118e4e89447cb51a/maintainability)](https://codeclimate.com/github/mfpiccolo/minitest-vcr/maintainability)
| Homepage | [http://mfpiccolo.github.io/minitest-vcr][homepage] |
| Documentation | [http://rdoc.info/github/mfpiccolo/minitest-vcr/frames][documentation] |
| Issues | [https://github.com/mfpiccolo/minitest-vcr/issues][issues] |
Expand Down
42 changes: 10 additions & 32 deletions Rakefile
@@ -1,39 +1,17 @@
# encoding: utf-8

require 'rubygems'

begin
require 'bundler'
rescue LoadError => e
warn e.message
warn "Run `gem install bundler` to install Bundler."
exit -1
end

begin
Bundler.setup(:development)
rescue Bundler::BundlerError => e
warn e.message
warn "Run `bundle install` to install missing gems."
exit e.status_code
end

require 'rake'

require 'rubygems/tasks'
Gem::Tasks.new
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rake/testtask'

Rake::TestTask.new do |test|
test.libs << 'test'
test.pattern = 'test/**/*_test.rb'
test.verbose = true
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
t.verbose = true
end

task default: :test

require 'yard'
YARD::Rake::YardocTask.new
task :doc => :yard

task :default => :test

task doc: :yard
1 change: 1 addition & 0 deletions lib/minitest-vcr.rb
@@ -1,5 +1,6 @@
require "minitest-vcr/version"
require "minitest-vcr/spec"
require "minitest-vcr/active_support/test_case"

module MinitestVcr
def self.included(base)
Expand Down
35 changes: 35 additions & 0 deletions lib/minitest-vcr/active_support/test_case.rb
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require 'vcr'
require 'active_support/testing/metadata'

module MinitestVcr
module ActiveSupport
module TestCase
def before_setup
super

return unless metadata.key?(:vcr)

base_path = self.class.name.split('::').map do |p|
p.underscore.tr(' ', '_')
end

base_path = File.join(*base_path)

file_name = name.gsub(/^test_.\d+_/, ' ').strip.tr(' ', '_')
path = File.join(base_path, file_name)

options = metadata[:vcr].is_a?(Hash) ? metadata[:vcr] : {}

::VCR.insert_cassette(path, options)
end

def after_teardown
::VCR.eject_cassette if metadata.key?(:vcr)

super
end
end
end
end
39 changes: 9 additions & 30 deletions lib/minitest-vcr/spec.rb
Expand Up @@ -3,23 +3,24 @@

module MinitestVcr
module Spec

def self.configure!
run_before = lambda do |example|
module SetupAndTeardown
def setup
super
if metadata[:vcr]
options = metadata[:vcr].is_a?(Hash) ? metadata[:vcr] : {}
VCR.insert_cassette StringHelpers.vcr_path(example), options
VCR.insert_cassette StringHelpers.vcr_path(self), options
end
end

run_after = lambda do |example|
def teardown
super
::VCR.eject_cassette if metadata[:vcr]
end

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

def self.configure!
::MiniTest::Spec.send(:include, SetupAndTeardown)
end
end # Spec

module StringHelpers
Expand Down Expand Up @@ -55,25 +56,3 @@ def self.extract_example_description(example)

end
end # MinitestVcr

if defined? ActiveSupport::TestCase
class ActiveSupport::TestCase
def before_setup
super
if self.class.name.match("::vcr::")
base_path = self.class.name.split("::")
.map {|p| p.underscore.gsub(" ", "_") unless p == "vcr" }.join("/")

file_name = name.gsub(/^test_.\d+_/, " ").strip.gsub(" ", "_")
VCR.insert_cassette(base_path + "/" + file_name)
end
end

def after_teardown
if self.class.name.match("::vcr::")
::VCR.eject_cassette
end
super
end
end
end
29 changes: 15 additions & 14 deletions minitest-vcr.gemspec
@@ -1,5 +1,6 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'minitest-vcr/version'

Expand All @@ -13,20 +14,20 @@ Gem::Specification.new do |spec|
spec.homepage = ""
spec.license = "MIT"

spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_dependency "activesupport-testing-metadata", "~> 0.1.0"
spec.add_dependency "minispec-metadata", "~> 3.0"
spec.add_dependency "minitest", ">= 5.0"
spec.add_dependency "vcr", ">= 2.9"
spec.add_dependency "minitest", ">= 4.7.5"
spec.add_dependency "minispec-metadata", "~> 2.0"

spec.add_development_dependency "bundler", "~> 1.5"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "mocha", "~> 1.0"
spec.add_development_dependency "faraday", "~> 0.9"
spec.add_development_dependency "rubygems-tasks", "~> 0.2"
spec.add_development_dependency "yard", "~> 0.8"
spec.add_development_dependency "webmock", "~> 1.17"
spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "rake", "~> 10.0"
end

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/helper.rb
Expand Up @@ -19,6 +19,7 @@

require "minitest/autorun"
require "minispec-metadata"
require "active_support/testing/metadata"
require "vcr"
require "minitest-vcr"
require "webmock"
Expand Down
17 changes: 17 additions & 0 deletions test/minitest-vcr/active_support/test_case_test.rb
@@ -0,0 +1,17 @@
require "helper"

class ActiveSupport::TestCase
include MinitestVcr::ActiveSupport::TestCase
end

class MinitestVcr::ActiveSupport::TestCaseTest < ActiveSupport::TestCase
test 'create a cassette name with the proper path', :vcr do
conn = Faraday.new
@response = conn.get 'http://example.com'

expected = File.join(self.class.name.underscore, name)
actual = VCR.current_cassette.name

assert_equal expected, actual
end
end
8 changes: 2 additions & 6 deletions test/minitest-vcr/spec_test.rb
Expand Up @@ -43,13 +43,9 @@

describe "#configure!", :vcr do

before do
::MiniTest::Spec.expects(:before).with(:each)
::MiniTest::Spec.expects(:after).with(:each)
end

it "should call before and after with proper args and block" do
it "should include setup and teardown module into Minitest::Spec" do
MinitestVcr::Spec.configure!
Minitest::Spec.included_modules.must_include(MinitestVcr::Spec::SetupAndTeardown)
end
end
end

0 comments on commit 67bcc6c

Please sign in to comment.