/
lolcommits_steps.rb
71 lines (59 loc) · 2.21 KB
/
lolcommits_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
include FileUtils
Given /^I am in a directory named "(.*?)"$/ do |dir_name|
steps %Q{
Given a directory named "#{dir_name}"
And I cd to "#{dir_name}"
}
end
Given /^a git repository named "(.*?)"$/ do |repo_name|
repo_dir = File.join current_dir, repo_name
mkdir_p repo_dir
Dir.chdir repo_dir do
sh "git init --quiet ."
end
end
Given /^the git repository named "(.*?)" has no "(.*?)" hook$/ do |repo_name, hook_name|
hook_file = File.join current_dir, repo_name, ".git", "hooks", hook_name
delete(hook_file) if File.exists? hook_file
end
Given /^the git repository named "(.*?)" has a "(.*?)" hook$/ do |repo_name, hook_name|
hook_file = File.join current_dir, repo_name, ".git", "hooks", hook_name
touch(hook_file) if not File.exists? hook_file
end
Given /^a git repository named "(.*?)" with (a|no) "(.*?)" hook$/ do |repo_name, yesno_modifier, hook_name|
step %{a git repository named "#{repo_name}"}
step %{the git repository named "#{repo_name}" has #{yesno_modifier} "#{hook_name}" hook}
end
Given /^I am in a git repository named "(.*?)" with lolcommits enabled$/ do |repo_name|
steps %Q{
Given a git repository named "#{repo_name}"
And I cd to "#{repo_name}"
And I successfully run `lolcommits --enable`
}
end
When /^I run `(.*?)` and wait for output$/ do |command|
command = "cd #{current_dir} && #{command}"
@stdin, @stdout, @stderr = Open3.popen3(command)
@fields = Hash.new
end
Given /^a loldir named "(.*?)" with (\d+) lolimages$/ do |repo_name, num_images|
loldir = "tmp/aruba/.lolcommits/#{repo_name}"
mkdir_p loldir
num_images.to_i.times do
random_hex = "%011x" % (rand * 0xfffffffffff)
cp "test/images/test_image.jpg", File.join( loldir, "#{random_hex}.jpg")
end
end
Then /^I should be (prompted for|presented) "(.*?)"$/ do |_, prompt|
assert @stdout.read.to_s.include?(prompt)
end
When /^I enter "(.*?)" for "(.*?)"$/ do |input, field|
@fields[field] = input
@stdin.puts input
end
Then /^there should be (?:exactly|only) (.*?) jpg(?:s?) in "(.*?)"$/ do |n, folder|
assert_equal n.to_i, Dir["#{current_dir}/#{folder}/*.jpg"].count
end
Then /^the output should contain a list of plugins$/ do
step %{the output should contain "Available plugins: "}
end