forked from ryanb/nifty-generators
/
common_steps.rb
50 lines (42 loc) · 1.65 KB
/
common_steps.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
When /^I run "([^\"]*)"$/ do |command|
system("cd #{@current_directory} && #{command}").should be_true
end
When /^I add "([^\"]*)" to file "([^\"]*)"$/ do |content, short_path|
path = File.join(@current_directory, short_path)
File.should exist(path)
File.open(path, 'a') { |f| f.write(content + "\n") }
end
When /^I replace "([^\"]*)" with "([^\"]*)" in file "([^\"]*)"$/ do |old_content, new_content, short_path|
path = File.join(@current_directory, short_path)
File.should exist(path)
content = File.read(path).gsub(old_content, new_content)
File.open(path, 'w') { |f| f.write(content) }
end
Then /^I should see file "([^\"]*)"$/ do |path|
File.should exist(File.join(@current_directory, path))
end
Then /^I should see "(.*)" in file "([^\"]*)"$/ do |content, short_path|
path = File.join(@current_directory, short_path)
File.should exist(path)
File.readlines(path).join.should include(content)
end
Then /^I should not see "(.*)" in file "([^\"]*)"$/ do |content, short_path|
path = File.join(@current_directory, short_path)
File.should exist(path)
File.readlines(path).join.should_not include(content)
end
Then /^I should see the following files$/ do |table|
table.raw.flatten.each do |path|
File.should exist(File.join(@current_directory, path))
end
end
Then /^I should see the following in file "([^\"]*)"$/ do |short_path, table|
path = File.join(@current_directory, short_path)
File.should exist(path)
table.raw.flatten.each do |content|
File.readlines(path).join.should include(content)
end
end
Then /^I should successfully run "([^\"]*)"$/ do |command|
system("cd #{@current_directory} && #{command}").should be_true
end