mirror of
https://github.com/thoughtbot/shoulda-matchers.git
synced 2022-11-09 12:01:38 -05:00
b7e02184d9
- bump rubocop to v1.0 - Fix Layout/MultilineAssignmentLayout and other remaining offences - Exculde appraisal generated gemfiles in rubocop - Replace NON_NUMERIC_VALUE constant with instance method against failing test case in rails <= 5.1 and postgres adapter. This is a defect in rails where a frozen string is modified in https://github.com/rails/rails/blob/v5.1.7/activerecord/lib/active_record/connection_adapters/postgresql/oid/money.rb#L25
98 lines
1.8 KiB
Ruby
98 lines
1.8 KiB
Ruby
require_relative 'filesystem'
|
|
require_relative 'command_runner'
|
|
require_relative 'version'
|
|
|
|
module Tests
|
|
class Bundle
|
|
def initialize
|
|
@already_updating = false
|
|
@fs = Filesystem.new
|
|
end
|
|
|
|
def updating
|
|
if already_updating?
|
|
yield self
|
|
return
|
|
end
|
|
|
|
@already_updating = true
|
|
|
|
yield self
|
|
|
|
@already_updating = false
|
|
|
|
install_gems
|
|
end
|
|
|
|
def add_gem(gem, *args)
|
|
updating do
|
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
|
version = args.shift
|
|
line = assemble_gem_line(gem, version, options)
|
|
fs.append_to_file('Gemfile', line)
|
|
end
|
|
end
|
|
|
|
def remove_gem(gem)
|
|
updating do
|
|
fs.comment_lines_matching('Gemfile', /^ *gem ("|')#{gem}\1/)
|
|
end
|
|
end
|
|
|
|
def install_gems
|
|
CommandRunner.run!('bundle install --local') do |runner|
|
|
runner.retries = 5
|
|
end
|
|
end
|
|
|
|
def version_of(gem)
|
|
Version.new(Bundler.definition.specs[gem][0].version)
|
|
end
|
|
|
|
def includes?(gem)
|
|
Bundler.definition.dependencies.any? do |dependency|
|
|
dependency.name == gem
|
|
end
|
|
end
|
|
|
|
def version
|
|
Bundler::VERSION
|
|
end
|
|
|
|
protected
|
|
|
|
attr_reader :fs
|
|
|
|
private
|
|
|
|
def already_updating?
|
|
@already_updating
|
|
end
|
|
|
|
def assemble_gem_line(gem, version, options)
|
|
formatted_options = options.
|
|
map { |key, value| "#{key}: #{formatted_value(value)}" }.
|
|
join(', ')
|
|
|
|
line = %(gem '#{gem}')
|
|
|
|
if version
|
|
line << %(, '#{version}')
|
|
end
|
|
|
|
if options.any?
|
|
line << %(, #{formatted_options})
|
|
end
|
|
|
|
line << "\n"
|
|
end
|
|
|
|
def formatted_value(value)
|
|
if value.is_a?(Pathname)
|
|
value.to_s.inspect
|
|
else
|
|
value.inspect
|
|
end
|
|
end
|
|
end
|
|
end
|