Skip to content

Commit

Permalink
Enable webmock alongside installing the gem (#7)
Browse files Browse the repository at this point in the history
Before, webmock was installed purely as an adapter for vcr. But it is
often useful to have the webmock DSL available to use directly. This
commit adds the necessary `require` statement to enable the webmock DSL
within minitest and rspec.
  • Loading branch information
mattbrictson authored Oct 25, 2023
1 parent 6edabe4 commit 3350078
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/generators.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ tomo:

vcr:
prompt: "VCR"
description: "Install and configure the vcr gem"
description: "Install and configure vcr and webmock gems"
requires: test_framework

rubocop:
Expand Down
1 change: 1 addition & 0 deletions lib/nextgen/generators/vcr.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
install_gems "vcr", "webmock", group: :test
copy_test_support_file "webmock.rb"
template "test/support/vcr.rb.tt", rspec? ? "spec/support/vcr.rb" : "test/support/vcr.rb"
1 change: 1 addition & 0 deletions template/spec/support/webmock.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "webmock/rspec"
1 change: 1 addition & 0 deletions template/test/support/webmock.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "webmock/minitest"
17 changes: 15 additions & 2 deletions test/nextgen/generators/vcr_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,24 @@ class Nextgen::Generators::VcrTest < Nextgen::Generators::TestCase
end
end

test "adds a test/support/vcr.rb file" do
test "when minitest is present, adds vcr and webmock test support files" do
Dir.chdir(destination_root) do
FileUtils.mkdir_p("test")
FileUtils.touch("test/test_helper.rb")
end

apply_generator

assert_file "test/support/vcr.rb" do |support|
refute_match(/rspec/, support)
end

assert_file "test/support/webmock.rb" do |support|
assert_match('require "webmock/minitest"', support)
end
end

test "when rspec is present, adds a spec/support/vcr.rb file" do
test "when rspec is present, adds vcr and webmock spec support files" do
Dir.chdir(destination_root) do
FileUtils.mkdir_p("spec/support")
FileUtils.touch("spec/spec_helper.rb")
Expand All @@ -38,5 +47,9 @@ class Nextgen::Generators::VcrTest < Nextgen::Generators::TestCase
assert_file "spec/support/vcr.rb" do |support|
assert_match(/rspec/, support)
end

assert_file "spec/support/webmock.rb" do |support|
assert_match('require "webmock/rspec"', support)
end
end
end

0 comments on commit 3350078

Please sign in to comment.