/
commands_spec.rb
292 lines (239 loc) · 8.06 KB
/
commands_spec.rb
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
require File.expand_path("spec_helper", File.dirname(__FILE__))
require File.expand_path("../lib/nesta/commands", File.dirname(__FILE__))
describe "nesta" do
include FixtureHelper
before(:each) do
create_fixtures_directory
@project_path = File.join(FixtureHelper::FIXTURE_DIR, 'mysite.com')
end
after(:each) do
remove_fixtures
end
def project_path(path)
File.join(@project_path, path)
end
def should_exist(file)
File.exist?(project_path(file)).should be_true
end
def create_config_yaml(text)
File.open(Nesta::Config.yaml_path, 'w') { |f| f.puts(text) }
end
describe "new" do
def gemfile_source
File.read(project_path('Gemfile'))
end
def rakefile_source
File.read(project_path('Rakefile'))
end
describe "without options" do
before(:each) do
Nesta::Commands::New.new(@project_path).execute
end
it "should create the content directories" do
should_exist('content/attachments')
should_exist('content/pages')
end
it "should create the home page" do
should_exist('content/pages/index.haml')
end
it "should create the rackup file" do
should_exist('config.ru')
end
it "should create the config.yml file" do
should_exist('config/config.yml')
end
it "should add a Gemfile" do
should_exist('Gemfile')
gemfile_source.should match(/gem 'nesta', '#{Nesta::VERSION}'/)
end
end
describe "--git" do
before(:each) do
@command = Nesta::Commands::New.new(@project_path, 'git' => '')
@command.stub!(:system)
end
it "should create a .gitignore file" do
@command.execute
File.read(project_path('.gitignore')).should match(/\.bundle/)
end
it "should create a git repo" do
@command.should_receive(:system).with('git', 'init')
@command.execute
end
it "should commit the blank project" do
@command.should_receive(:system).with('git', 'add', '.')
@command.should_receive(:system).with(
'git', 'commit', '-m', 'Initial commit')
@command.execute
end
end
describe "--vlad" do
before(:each) do
Nesta::Commands::New.new(@project_path, 'vlad' => '').execute
end
it "should add vlad to Gemfile" do
gemfile_source.should match(/gem 'vlad', '2.1.0'/)
gemfile_source.should match(/gem 'vlad-git', '2.2.0'/)
end
it "should configure the vlad rake tasks" do
should_exist('Rakefile')
rakefile_source.should match(/require 'vlad'/)
end
it "should create deploy.rb" do
should_exist('config/deploy.rb')
deploy_source = File.read(project_path('config/deploy.rb'))
deploy_source.should match(/set :application, 'mysite.com'/)
end
end
end
describe "demo:content" do
before(:each) do
@config_path = project_path('config/config.yml')
FileUtils.mkdir_p(File.dirname(@config_path))
Nesta::Config.stub!(:yaml_path).and_return(@config_path)
create_config_yaml('content: path/to/content')
Nesta::Env.stub!(:root).and_return(@project_path)
@repo_url = 'git://github.com/gma/nesta-demo-content.git'
@demo_path = project_path('content-demo')
@command = Nesta::Commands::Demo::Content.new
@command.stub!(:system)
end
it "should clone the repository" do
@command.should_receive(:system).with(
'git', 'clone', @repo_url, @demo_path)
@command.execute
end
it "should configure the content directory" do
@command.execute
File.read(@config_path).should match(/^content: content-demo/)
end
describe "when repository already exists" do
before(:each) do
FileUtils.mkdir_p(@demo_path)
end
it "should update the repository" do
@command.should_receive(:system).with('git', 'pull', 'origin', 'master')
@command.execute
end
end
describe "when site versioned with git" do
before(:each) do
@exclude_path = project_path('.git/info/exclude')
FileUtils.mkdir_p(File.dirname(@exclude_path))
File.open(@exclude_path, 'w') { |file| file.puts '# Excludes' }
end
it "should tell git to ignore content-demo" do
@command.execute
File.read(@exclude_path).should match(/content-demo/)
end
describe "and content-demo already ignored" do
before(:each) do
File.open(@exclude_path, 'w') { |file| file.puts 'content-demo' }
end
it "shouldn't tell git to ignore it twice" do
@command.execute
File.read(@exclude_path).scan('content-demo').size.should == 1
end
end
end
end
describe "theme:install" do
before(:each) do
@repo_url = 'git://github.com/gma/nesta-theme-mine.git'
@theme_dir = 'themes/mine'
FileUtils.mkdir_p(File.join(@theme_dir, '.git'))
@command = Nesta::Commands::Theme::Install.new(@repo_url)
@command.stub!(:system)
end
after(:each) do
FileUtils.rm_r(@theme_dir)
end
it "should clone the repository" do
@command.should_receive(:system).with(
'git', 'clone', @repo_url, @theme_dir)
@command.execute
end
it "should remove the theme's .git directory" do
@command.execute
File.exist?(@theme_dir).should be_true
File.exist?(File.join(@theme_dir, '.git')).should be_false
end
it "should enable the freshly installed theme" do
@command.should_receive(:enable).with('mine')
@command.execute
end
describe "when theme URL doesn't match recommendation" do
before(:each) do
@repo_url = 'git://foobar.com/path/to/mytheme.git'
@other_theme_dir = 'themes/mytheme'
FileUtils.mkdir_p(File.join(@other_theme_dir, '.git'))
@command = Nesta::Commands::Theme::Install.new(@repo_url)
end
after(:each) do
FileUtils.rm_r(@other_theme_dir)
end
it "should use the basename as theme dir" do
@command.should_receive(:system).with(
'git', 'clone', @repo_url, @other_theme_dir)
@command.execute
end
end
end
describe "theme:enable" do
before(:each) do
config = File.join(FixtureHelper::FIXTURE_DIR, 'config.yml')
Nesta::Config.stub!(:yaml_path).and_return(config)
@name = 'mytheme'
@command = Nesta::Commands::Theme::Enable.new(@name)
end
shared_examples_for "command that configures the theme" do
it "should enable the theme" do
@command.execute
File.read(Nesta::Config.yaml_path).should match(/^theme: #{@name}/)
end
end
describe "when theme config is commented out" do
before(:each) do
create_config_yaml(' # theme: blah')
end
it_should_behave_like "command that configures the theme"
end
describe "when another theme is configured" do
before(:each) do
create_config_yaml('theme: another')
end
it_should_behave_like "command that configures the theme"
end
describe "when no theme config exists" do
before(:each) do
create_config_yaml('# I have no theme config')
end
it_should_behave_like "command that configures the theme"
end
end
describe "theme:create" do
def should_exist(file)
File.exist?(Nesta::Path.themes(@name, file)).should be_true
end
before(:each) do
Nesta::Env.stub!(:root).and_return(FixtureHelper::FIXTURE_DIR)
@name = 'my-new-theme'
Nesta::Commands::Theme::Create.new(@name).execute
end
it "should create the theme directory" do
File.directory?(Nesta::Path.themes(@name)).should be_true
end
it "should create a dummy README file" do
should_exist('README.md')
text = File.read(Nesta::Path.themes(@name, 'README.md'))
text.should match(/#{@name} is a theme/)
end
it "should create a default app.rb file" do
should_exist('app.rb')
end
it "should create public and view directories" do
should_exist("public/#{@name}")
should_exist('views')
end
end
end