guard-cucumber 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/guard/cucumber.rb +24 -2
- data/lib/guard/cucumber/cucumber_formatter.rb +32 -0
- data/lib/guard/cucumber/runner.rb +12 -34
- data/lib/guard/cucumber/version.rb +1 -1
- metadata +5 -4
data/lib/guard/cucumber.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'guard'
|
2
2
|
require 'guard/guard'
|
3
|
+
require 'cucumber'
|
3
4
|
|
4
5
|
module Guard
|
5
6
|
class Cucumber < Guard
|
@@ -7,13 +8,34 @@ module Guard
|
|
7
8
|
autoload :Runner, 'guard/cucumber/runner'
|
8
9
|
autoload :Inspector, 'guard/cucumber/inspector'
|
9
10
|
|
11
|
+
attr_reader :configuration, :runtime
|
12
|
+
|
13
|
+
def start
|
14
|
+
UI.info 'Preload cucumber environment. This could take a while...'
|
15
|
+
|
16
|
+
@configuration = ::Cucumber::Cli::Configuration.new
|
17
|
+
@runtime = ::Cucumber::Runtime.new(@configuration)
|
18
|
+
@configuration.parse!(['features'])
|
19
|
+
|
20
|
+
# Hack the support code, since loading the files takes most of the initialization time
|
21
|
+
@support = ::Cucumber::Runtime::SupportCode.new(@runtime, @configuration)
|
22
|
+
@support.load_files!(@configuration.support_to_load + @configuration.step_defs_to_load)
|
23
|
+
@support.fire_hook(:after_configuration, @configuration)
|
24
|
+
@runtime.instance_variable_set('@support_code', @support)
|
25
|
+
|
26
|
+
UI.info 'Cucumber environment loaded.'
|
27
|
+
end
|
28
|
+
|
10
29
|
def run_all
|
11
|
-
|
30
|
+
configuration.parse!(['features'])
|
31
|
+
Runner.run runtime, configuration, options.merge!({ :message => 'Run all Cucumber features' })
|
12
32
|
end
|
13
33
|
|
14
34
|
def run_on_change(paths)
|
15
35
|
paths = Inspector.clean(paths)
|
16
|
-
|
36
|
+
options.merge!({ :message => 'Run all Cucumber features' }) if paths.include?('features')
|
37
|
+
configuration.parse!(paths)
|
38
|
+
Runner.run(runtime, configuration, options) unless paths.empty?
|
17
39
|
end
|
18
40
|
|
19
41
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'cucumber/formatter/progress'
|
2
|
+
|
3
|
+
class CucumberFormatter < Cucumber::Formatter::Progress
|
4
|
+
|
5
|
+
def print_stats(features, profiles = [])
|
6
|
+
super features, profiles
|
7
|
+
|
8
|
+
icon, messages = '', []
|
9
|
+
[:failed, :skipped, :undefined, :pending, :passed].reverse.each do |status|
|
10
|
+
if step_mother.steps(status).any?
|
11
|
+
icon = icon_for(status)
|
12
|
+
messages << dump_count(step_mother.steps(status).length, 'step', status.to_s)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
::Guard::Notifier.notify messages.reverse.join(', '), :title => 'Cucumber Results', :image => icon
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def icon_for(status)
|
22
|
+
case status
|
23
|
+
when :passed
|
24
|
+
:success
|
25
|
+
when :pending, :undefined, :skipped
|
26
|
+
:pending
|
27
|
+
when :failed
|
28
|
+
:failed
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -1,49 +1,27 @@
|
|
1
|
-
require '
|
1
|
+
require 'cucumber'
|
2
|
+
require 'guard/cucumber/cucumber_formatter'
|
2
3
|
|
3
4
|
module Guard
|
4
5
|
class Cucumber
|
5
6
|
module Runner
|
6
7
|
class << self
|
7
|
-
include Open3
|
8
8
|
|
9
|
-
def run(
|
10
|
-
|
9
|
+
def run(runtime, configuration, options = {})
|
10
|
+
features = configuration.feature_files
|
11
|
+
message = options[:message] || run_message(features)
|
11
12
|
UI.info message, :reset => true
|
12
13
|
|
13
|
-
|
14
|
-
::Guard::Notifier.notify(message, :title => 'Cucumber results', :image => (status == 0 ? :success : :failed))
|
14
|
+
run_cucumber(features, runtime, configuration)
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
while !output.eof?
|
26
|
-
line = output.readline
|
27
|
-
message << line if line =~ /^\d+ (steps|scenarios)/
|
28
|
-
puts line
|
29
|
-
end
|
30
|
-
status = wait_thread.value
|
31
|
-
end
|
32
|
-
|
33
|
-
[status, message.gsub(/\[\d+m\d*?/, '')]
|
34
|
-
end
|
35
|
-
|
36
|
-
def cucumber_command(paths)
|
37
|
-
cmd = []
|
38
|
-
cmd << 'bundle exec' if bundler?
|
39
|
-
cmd << 'cucumber'
|
40
|
-
cmd << '--color'
|
41
|
-
cmd = cmd + paths
|
42
|
-
cmd.join(' ')
|
43
|
-
end
|
44
|
-
|
45
|
-
def bundler?
|
46
|
-
@bundler ||= File.exist?("#{Dir.pwd}/Gemfile")
|
19
|
+
def run_cucumber(features, runtime, configuration)
|
20
|
+
formatter = CucumberFormatter.new(runtime, $stdout, configuration.instance_variable_get('@options'))
|
21
|
+
runner = ::Cucumber::Ast::TreeWalker.new(runtime, [formatter], configuration)
|
22
|
+
runtime.visitor = runner
|
23
|
+
loader = ::Cucumber::Runtime::FeaturesLoader.new(features, configuration.filters, configuration.tag_expression)
|
24
|
+
runner.visit_features(loader.features)
|
47
25
|
end
|
48
26
|
|
49
27
|
def run_message(paths)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-cucumber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Kessler
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-29 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -108,6 +108,7 @@ extensions: []
|
|
108
108
|
extra_rdoc_files: []
|
109
109
|
|
110
110
|
files:
|
111
|
+
- lib/guard/cucumber/cucumber_formatter.rb
|
111
112
|
- lib/guard/cucumber/inspector.rb
|
112
113
|
- lib/guard/cucumber/runner.rb
|
113
114
|
- lib/guard/cucumber/templates/Guardfile
|