Class: Boring::Vcr::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Boring::Vcr::InstallGenerator
show all
- Includes:
- BoringGenerators::GeneratorHelper
- Defined in:
- lib/generators/boring/vcr/install/install_generator.rb
Instance Method Summary
collapse
#app_ruby_version, #bundle_install, #check_and_install_gem, #gem_installed?, #inject_into_file_if_new
Instance Method Details
#add_stubbing_library_gems ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/generators/boring/vcr/install/install_generator.rb', line 53
def add_stubbing_library_gems
say "Adding stubbing library gems to Gemfile", :green
options[:stubbing_libraries].uniq.each do |stubbing_library|
check_and_install_gem stubbing_library, group: :test
end
end
|
#add_vcr_gem ⇒ Object
47
48
49
50
51
|
# File 'lib/generators/boring/vcr/install/install_generator.rb', line 47
def add_vcr_gem
say "Adding VCR gems to Gemfile", :green
check_and_install_gem "vcr", group: :test
end
|
#setup_vcr_for_minitest ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/generators/boring/vcr/install/install_generator.rb', line 77
def setup_vcr_for_minitest
return unless minitest?
say "Setting up VCR for Minitest", :green
vcr_config = <<~RUBY
require "vcr"
VCR.configure do |c|
c.cassette_library_dir = "test/vcr_cassettes"
c.hook_into #{format_stubbing_libraries}
c.ignore_localhost = true
c.allow_http_connections_when_no_cassette = true
end
RUBY
inject_into_file "test/test_helper.rb", vcr_config, end: /^end\s*\Z/m
end
|
#setup_vcr_for_rspec ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/generators/boring/vcr/install/install_generator.rb', line 61
def setup_vcr_for_rspec
return unless rspec?
say "Setting up VCR for RSpec", :green
@stubbing_libraries = format_stubbing_libraries
template("rspec/vcr.rb", "spec/support/vcr.rb")
unless all_support_files_are_required?
inject_into_file "spec/rails_helper.rb",
"require 'support/vcr'\n\n",
before: /\A/
end
end
|
#verify_presence_of_rails_helper ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/generators/boring/vcr/install/install_generator.rb', line 38
def verify_presence_of_rails_helper
return if minitest? || (rspec? && File.exist?("spec/rails_helper.rb"))
say "We couldn't find spec/rails_helper.rb. Please configure RSpec and rerun the generator. Consider running `rails generate boring:rspec:install` to set up RSpec.",
:red
abort
end
|
#verify_presence_of_test_helper ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/generators/boring/vcr/install/install_generator.rb', line 29
def verify_presence_of_test_helper
return if rspec? || (minitest? && File.exist?("test/test_helper.rb"))
say "We couldn't find test/test_helper.rb. Please configure Minitest and rerun the generator.",
:red
abort
end
|