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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
require 'spec_helper'
describe Bundler::Dsl do
before do
@rubygems = double("rubygems")
allow(Bundler::Source::Rubygems).to receive(:new){ @rubygems }
end
describe "#git_source" do
it "registers custom hosts" do
subject.git_source(:example){ |repo_name| "git@git.example.com:#{repo_name}.git" }
subject.git_source(:foobar){ |repo_name| "git@foobar.com:#{repo_name}.git" }
subject.gem("dobry-pies", :example => "strzalek/dobry-pies")
example_uri = "git@git.example.com:strzalek/dobry-pies.git"
expect(subject.dependencies.first.source.uri).to eq(example_uri)
end
it "raises expection on invalid hostname" do
expect {
subject.git_source(:group){ |repo_name| "git@git.example.com:#{repo_name}.git" }
}.to raise_error(Bundler::InvalidOption)
end
it "expects block passed" do
expect{ subject.git_source(:example) }.to raise_error(Bundler::InvalidOption)
end
context "default hosts (git, gist)" do
it "converts :github to :git" do
subject.gem("sparks", :github => "indirect/sparks")
github_uri = "git://github.com/indirect/sparks.git"
expect(subject.dependencies.first.source.uri).to eq(github_uri)
end
it "converts numeric :gist to :git" do
subject.gem("not-really-a-gem", :gist => 2859988)
github_uri = "https://gist.github.com/2859988.git"
expect(subject.dependencies.first.source.uri).to eq(github_uri)
end
it "converts :gist to :git" do
subject.gem("not-really-a-gem", :gist => "2859988")
github_uri = "https://gist.github.com/2859988.git"
expect(subject.dependencies.first.source.uri).to eq(github_uri)
end
it "converts 'rails' to 'rails/rails'" do
subject.gem("rails", :github => "rails")
github_uri = "git://github.com/rails/rails.git"
expect(subject.dependencies.first.source.uri).to eq(github_uri)
end
it "converts :bitbucket to :git" do
subject.gem("not-really-a-gem", :bitbucket => "mcorp/flatlab-rails")
bitbucket_uri = "https://mcorp@bitbucket.org/mcorp/flatlab-rails.git"
expect(subject.dependencies.first.source.uri).to eq(bitbucket_uri)
end
it "converts 'mcorp' to 'mcorp/mcorp'" do
subject.gem("not-really-a-gem", :bitbucket => "mcorp")
bitbucket_uri = "https://mcorp@bitbucket.org/mcorp/mcorp.git"
expect(subject.dependencies.first.source.uri).to eq(bitbucket_uri)
end
end
end
describe "#method_missing" do
it "raises an error for unknown DSL methods" do
expect(Bundler).to receive(:read_file).with("Gemfile").
and_return("unknown")
error_msg = "Undefined local variable or method `unknown'" \
" for Gemfile\\s+from Gemfile:1"
expect { subject.eval_gemfile("Gemfile") }.
to raise_error(Bundler::GemfileError, Regexp.new(error_msg))
end
end
describe "#eval_gemfile" do
it "handles syntax errors with a useful message" do
expect(Bundler).to receive(:read_file).with("Gemfile").and_return("}")
expect { subject.eval_gemfile("Gemfile") }.
to raise_error(Bundler::GemfileError, /Gemfile syntax error/)
end
end
describe "#gem" do
[:ruby, :ruby_18, :ruby_19, :ruby_20, :ruby_21, :mri, :mri_18, :mri_19,
:mri_20, :mri_21, :jruby, :rbx].each do |platform|
it "allows #{platform} as a valid platform" do
subject.gem("foo", :platform => platform)
end
end
it "rejects invalid platforms" do
expect { subject.gem("foo", :platform => :bogus) }.
to raise_error(Bundler::GemfileError, /is not a valid platform/)
end
it "rejects with a leading space in the name" do
expect { subject.gem(" foo") }.
to raise_error(Bundler::GemfileError, /' foo' is not a valid gem name because it contains whitespace/)
end
it "rejects with a trailing space in the name" do
expect { subject.gem("foo ") }.
to raise_error(Bundler::GemfileError, /'foo ' is not a valid gem name because it contains whitespace/)
end
it "rejects with a space in the gem name" do
expect { subject.gem("fo o") }.
to raise_error(Bundler::GemfileError, /'fo o' is not a valid gem name because it contains whitespace/)
end
it "rejects with a tab in the gem name" do
expect { subject.gem("fo\to") }.
to raise_error(Bundler::GemfileError, /'fo\to' is not a valid gem name because it contains whitespace/)
end
it "rejects with a newline in the gem name" do
expect { subject.gem("fo\no") }.
to raise_error(Bundler::GemfileError, /'fo\no' is not a valid gem name because it contains whitespace/)
end
it "rejects with a carriage return in the gem name" do
expect { subject.gem("fo\ro") }.
to raise_error(Bundler::GemfileError, /'fo\ro' is not a valid gem name because it contains whitespace/)
end
it "rejects with a form feed in the gem name" do
expect { subject.gem("fo\fo") }.
to raise_error(Bundler::GemfileError, /'fo\fo' is not a valid gem name because it contains whitespace/)
end
it "rejects symbols as gem name" do
expect { subject.gem(:foo) }.
to raise_error(Bundler::GemfileError, /You need to specify gem names as Strings. Use 'gem "foo"' instead/)
end
end
describe "syntax errors" do
it "will raise a Bundler::GemfileError" do
gemfile "gem 'foo', :path => /unquoted/string/syntax/error"
expect { Bundler::Dsl.evaluate(bundled_app("Gemfile"), nil, true) }.
to raise_error(Bundler::GemfileError, /Gemfile syntax error/)
end
end
end
|