-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathcommand_line_steps.rb
More file actions
268 lines (214 loc) · 7.52 KB
/
command_line_steps.rb
File metadata and controls
268 lines (214 loc) · 7.52 KB
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
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '../../test')))
require 'bundler/setup'
require 'test_helper'
require 'compass/exec'
include Compass::TestCaseHelper
include Compass::CommandLineHelper
include Compass::IoHelper
Before do
Compass.reset_configuration!
@cleanup_directories = []
@original_working_directory = Dir.pwd
end
After do
Dir.chdir @original_working_directory
@cleanup_directories.each do |dir|
FileUtils.rm_rf dir
end
end
Given "ruby supports fork" do
if RUBY_PLATFORM == "java"
pending
end
end
# Given Preconditions
Given %r{^I am using the existing project in ([^\s]+)$} do |project|
tmp_project = "tmp_#{File.basename(project)}"
@cleanup_directories << tmp_project
FileUtils.cp_r project, tmp_project
Dir.chdir tmp_project
end
Given %r{^I am in the parent directory$} do
Dir.chdir ".."
end
Given /^I should clean up the directory: (\w+)$/ do |directory|
@cleanup_directories << directory
end
Given %r{^the project has a file named "([^"]*)" containing:$} do |arg1, string|
File.open(arg1, "w") do |f|
f << string
end
end
# When Actions are performed
When /^I create a project using: compass create ([^\s]+) ?(.+)?$/ do |dir, args|
@cleanup_directories << dir
compass 'create', dir, *(args || '').split
end
When /^I initialize a project using: compass init ?(.+)?$/ do |args|
compass 'init', *(args || '').split
end
When /^I run: compass ([^\s]+) ?(.+)?$/ do |command, args|
compass command, *(args || '').split
end
When /^I run in a separate process: compass ([^\s]+) ?(.+)?$/ do |command, args|
unless @other_process = fork
@last_result = ''
@last_error = ''
Signal.trap("HUP") do
open('/tmp/last_result.compass_test.txt', 'w') do |file|
file.puts $stdout.string
end
open('/tmp/last_error.compass_test.txt', 'w') do |file|
file.puts $stderr.string
end
exit!
end
# this command will run forever
# we kill it with a HUP signal from the parent process.
args = (args || '').split
args << { :wait => 5 }
compass command, *args
exit!
end
end
When /^I shutdown the other process$/ do
Process.kill("HUP", @other_process)
Process.wait
@last_result = File.read('/tmp/last_result.compass_test.txt')
@last_error = File.read('/tmp/last_error.compass_test.txt')
end
When /^I touch ([^\s]+)$/ do |filename|
FileUtils.touch filename
end
When /^I wait ([\d.]+) seconds?$/ do |count|
sleep count.to_f
end
When /^I add some sass to ([^\s]+)$/ do |filename|
open(filename, "w+") do |file|
file.puts ".added .some .arbitrary"
file.puts " sass: code"
end
end
# Then postconditions
Then /^a directory ([^ ]+) is (not )?created$/ do |directory, negated|
File.directory?(directory).should == !negated
end
Then /an? \w+ file ([^ ]+) is (not )?removed/ do |filename, negated|
File.exist?(filename).should == !!negated
end
Then /an? \w+ file ([^ ]+) is (not )?created/ do |filename, negated|
File.exist?(filename).should == !negated
end
Then "the following files are reported removed:" do |table|
table.rows.each do |css_file|
#need to find a better way but this works for now
step %Q{a css file #{css_file.first} is reported removed}
end
end
Then "the following files are removed:" do |table|
table.rows.each do |css_file|
step %Q{a css file #{css_file.first} is removed}
end
end
Then /an? \w+ file ([^ ]+) is reported removed/ do |filename|
@last_result.should =~ /delete.*#{Regexp.escape(filename)}/
end
Then /an? \w+ file ([^ ]+) is reported written/ do |filename|
@last_result.should =~ /write.*#{Regexp.escape(filename)}/
end
Then /a \w+ file ([^ ]+) is (?:reported )?compiled/ do |filename|
@last_result.should =~ /compile.*#{Regexp.escape(filename)}/
end
Then /a \w+ file ([^ ]+) is reported unchanged/ do |filename|
@last_result.should =~ /unchanged.*#{Regexp.escape(filename)}/
end
Then /a \w+ file ([^ ]+) is reported identical/ do |filename|
@last_result.should =~ /identical.*#{Regexp.escape(filename)}/
end
Then /a \w+ file ([^ ]+) is reported overwritten/ do |filename|
@last_result.should =~ /overwrite.*#{Regexp.escape(filename)}/
end
Then /a \w+ file ([^ ]+) is not mentioned/ do |filename|
@last_result.should_not =~ /#{Regexp.escape(filename)}/
end
Then /I am told how to link to ([^ ]+) for media "([^"]+)"/ do |stylesheet, media|
@last_result.should =~ %r{<link href="#{stylesheet}" media="#{media}" rel="stylesheet" type="text/css" />}
end
Then /I am told how to conditionally link "([^"]+)" to ([^ ]+) for media "([^"]+)"/ do |condition, stylesheet, media|
@last_result.should =~ %r{<!--\[if #{condition}\]>\s+<link href="#{stylesheet}" media="#{media}" rel="stylesheet" type="text/css" />\s+<!\[endif\]-->}mi
end
Then /^an error message is printed out: (.+)$/ do |error_message|
@last_error.should =~ Regexp.new(Regexp.escape(error_message))
end
Then /^the command exits with a non\-zero error code$/ do
@last_exit_code.should_not == 0
end
Then /^the command exits normally$/ do
@last_exit_code.should == 0
end
Then /^I am congratulated$/ do
@last_result.should =~ /Congratulations!/
end
Then /^I am told that I can place stylesheets in the ([^\s]+) subdirectory$/ do |subdir|
@last_result.should =~ /You may now add sass stylesheets to the #{subdir} subdirectory of your project./
end
Then /^I am told how to compile my sass stylesheets$/ do
@last_result.should =~ /You must compile your sass stylesheets into CSS when they change.\nThis can be done in one of the following ways:/
end
Then /^I should be shown a list of "([^"]+)" commands$/ do |kind|
@last_result.should =~ /^#{kind.capitalize} Commands:$/
@last_command_list = []
found = false
indent = nil
@last_result.split("\n").each do |line|
if line =~ /^#{kind.capitalize} Commands:$/
found = true
elsif found && line =~ /^\s+/
@last_command_list << line
elsif found && line =~ /^$|^\w/
break
end
end
end
Then /^the list of commands should describe the ([^ ]+) command$/ do |command|
@last_result.should =~ /^\s+\* #{command}\s+- [A-Z].+$/
end
Then /^the following configuration properties are set in ([^ ]+):$/ do |config_file, table|
config = Compass::Configuration::FileData.new_from_file(config_file)
table.hashes.each do |hash|
config.send(hash['property']).should == hash['value']
end
end
Then /^my css is validated$/ do
if @last_error =~ /The Compass CSS Validator could not be loaded/
pending "Missing Dependency: sudo gem install compass-validator"
else
@last_result.should =~ /files? validated/
end
end
Then /^I am informed that my css is valid.$/ do
@last_result.should =~ /Result: Valid/
end
Then /^I am told statistics for each file:$/ do |table|
# table is a Cucumber::Ast::Table
table.raw.each do |row|
re = Regexp.new row.join(' *\| *')
@last_result.should =~ re
end
end
Then /^I should see the following "([^"]+)" commands:$/ do |kind, table|
step %Q{I should be shown a list of "#{kind}" commands}
commands = @last_command_list.map{|c| c =~ /^\s+\* ([^ ]+)\s+- [A-Z].+$/; [$1]}
table.diff!(commands)
end
Then /^the image ([^ ]+) has a size of (\d+)x(\d+)$/ do |file, width, height|
# see http://snippets.dzone.com/posts/show/805
size = File.open(file, "rb") {|io| io.read}[0x10..0x18].unpack('NN')
size.should == [width.to_i, height.to_i]
end
Then /^I should see the following lines of output:$/ do |table|
table.diff!([['compass']])
end
Then /^I should see the following output: (.+)$/ do |expected|
(@last_result.strip + @last_error.strip).should == expected.gsub(/\$PROJECT_PATH/,Dir.pwd).strip
end