summaryrefslogtreecommitdiff
path: root/features/step_definitions/execution.rb
blob: b45a0768df0e39e651b6c614b7549b470d143610 (plain)
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
# FIXME: Make the Transform work
#
# Transform /^| on JRuby$/ do |step_arg|
#  / on JRuby/.match(step_arg) != nil
# end

Given %r{^I've already successfully executed rake task '(.*)'(| on JRuby)$} do |task_name, on_jruby|
  rake_cmd = "rake #{task_name}"
  rake_cmd = 'jruby -S ' << rake_cmd if on_jruby == ' on JRuby'
  emptyness = `#{rake_cmd} 2>&1`
  unless $?.success?
    warn emptyness
    raise "rake failed with #{$?.exitstatus}"
  end
end

When /^rake task '(.*)' is invoked(| on JRuby)$/ do |task_name, on_jruby|
  @output ||= {}
  @result ||= {}
  rake_cmd = "rake #{task_name}"
  rake_cmd = 'jruby -S ' << rake_cmd if on_jruby == ' on JRuby'
  @output[task_name] = `#{rake_cmd} 2>&1`
  @result[task_name] = $?.success?
end

Then /^rake task '(.*)' succeeded$/ do |task_name|
  if @result.nil? || !@result.include?(task_name) then
    raise "The task #{task_name} should be invoked first."
  else
    @result[task_name].should be_true
  end
end

Then /^rake task '(.*)' should fail$/ do |task_name|
  if @result.nil? || !@result.include?(task_name) then
    raise "The task #{task_name} should be invoked first."
  else
    @result[task_name].should be_false
  end
end

Then /^output of rake task '(.*)' (contains|do not contain) \/(.*)\/$/ do |task_name, condition, regex|
  if condition == 'contains' then
    @output[task_name].should match(%r(#{regex}))
  else
    @output[task_name].should_not match(%r(#{regex}))
  end
end

Then /^output of rake task '(.*)' warns$/ do |task_name, warning|
  STDERR.puts task_name.inspect
  STDERR.puts @output[task_name].inspect
  STDERR.puts warning.inspect
  @output[task_name].should include(warning)
end