1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# frozen_string_literal: true
module Spec
module Matchers
RSpec::Matchers.define :have_dep do |*args|
dep = Bundler::Dependency.new(*args)
match do |actual|
actual.length == 1 && actual.all? {|d| d == dep }
end
end
RSpec::Matchers.define :have_gem do |*args|
match do |actual|
actual.length == args.length && actual.all? {|a| args.include?(a.full_name) }
end
end
RSpec::Matchers.define :have_rubyopts do |*args|
args = args.flatten
args = args.first.split(/\s+/) if args.size == 1
match do |actual|
actual = actual.split(/\s+/) if actual.is_a?(String)
args.all? {|arg| actual.include?(arg) } && actual.uniq.size == actual.size
end
end
def should_be_installed(*names)
opts = names.last.is_a?(Hash) ? names.pop : {}
groups = Array(opts[:groups])
groups << opts
names.each do |name|
name, version, platform = name.split(/\s+/)
version_const = name == "bundler" ? "Bundler::VERSION" : Spec::Builders.constantize(name)
run! "require '#{name}.rb'; puts #{version_const}", *groups
expect(out).not_to be_empty, "#{name} is not installed"
actual_version, actual_platform = out.split(/\s+/, 2)
expect(Gem::Version.new(actual_version)).to eq(Gem::Version.new(version))
expect(actual_platform).to eq(platform)
end
end
alias_method :should_be_available, :should_be_installed
def should_not_be_installed(*names)
opts = names.last.is_a?(Hash) ? names.pop : {}
groups = Array(opts[:groups]) || []
names.each do |name|
name, version = name.split(/\s+/, 2)
run <<-R, *(groups + [opts])
begin
require '#{name}'
puts #{Spec::Builders.constantize(name)}
rescue LoadError, NameError
puts "WIN"
end
R
if version.nil? || out == "WIN"
expect(out).to eq("WIN")
else
expect(Gem::Version.new(out)).not_to eq(Gem::Version.new(version))
end
end
end
def plugin_should_be_installed(*names)
names.each do |name|
path = Plugin.installed?(name)
expect(path).to be_truthy
expect(Pathname.new(path).join("plugins.rb")).to exist
end
end
def should_be_locked
expect(bundled_app("Gemfile.lock")).to exist
end
def lockfile_should_be(expected)
should_be_locked
spaces = expected[/\A\s+/, 0] || ""
expected = expected.gsub(/^#{spaces}/, "")
expect(bundled_app("Gemfile.lock").read).to eq(expected)
end
end
end
|