multicuke 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ module Multicuke
2
+
3
+ # Generate the index page reporting on the features and their status.
4
+ # Provides the links to the actual full Cucumber html reports.
5
+ class ReportsIndex
6
+
7
+ # Collection of ran features directories results used for reporting
8
+ attr_reader :features_dirs
9
+
10
+ def initialize(reports_path, features_dirs)
11
+ @features_dirs = features_dirs
12
+ @index_file_path = File.join(reports_path, "index.html")
13
+ end
14
+
15
+ def generate
16
+ index_file = File.new(@index_file_path, "w")
17
+
18
+ b = Builder::XmlMarkup.new :target => index_file, :indent => 2
19
+ b.html {
20
+ b.head {
21
+ b.title("Cucumber reports")
22
+ b.style(css_content)
23
+ }
24
+ b.body {
25
+ b.h2("Features")
26
+ b.ul {
27
+ features_dirs.each { |features_dir|
28
+ b.li(:class => (features_dir.failed? ? "failed" : "success")) {
29
+ b.a(features_dir.human_name, :href => "#{features_dir.name}.html")
30
+ b.span("[#{features_dir.duration}]", :class => "duration")
31
+ b.span("Scenarios: #{features_dir.scenarios_results}, Steps: #{features_dir.steps_results}", :class => "result")
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
37
+
38
+ index_file.close
39
+ end
40
+
41
+ private
42
+
43
+ def css_content
44
+ <<-CSS
45
+ body {font-family: "Lucida Grande", Helvetica, sans-serif; margin: 2em 8em 2em 8em;}
46
+ ul {list-style-type: square;}
47
+ li {margin: 1em 0 1em 0;}
48
+ li span {float: right; margin-left: 1em; padding: 0 0.3em;}
49
+ li.failed span.result{background: #DC6E6E;}
50
+ li.success span.result{background: #C1E799;}
51
+ span.duration {color: #999999;}
52
+ CSS
53
+ end
54
+
55
+ end
56
+ end
@@ -1,7 +1,7 @@
1
1
  require 'fileutils'
2
2
  require 'builder'
3
3
  require 'nokogiri'
4
- require 'ostruct'
4
+ require 'multicuke/reports_index'
5
5
 
6
6
  module Multicuke
7
7
 
@@ -38,12 +38,27 @@ module Multicuke
38
38
 
39
39
  end
40
40
 
41
+ # Actual clas that will spawn one command process per directory of features collected
42
+ # according to configuration
41
43
  class Runner
42
44
 
43
- attr_accessor :features_dir_path
45
+ # Root path to your features directory
46
+ attr_accessor :features_root_path
47
+
48
+ # Optional name for directory containing the reports
44
49
  attr_accessor :output_dir_name
50
+
51
+ # Optional full path for generated reports. Default to where it is run from.
45
52
  attr_accessor :output_path
46
- attr_accessor :excluded_dirs, :reports_path, :dry_run
53
+
54
+ # Optional features directories to exclude
55
+ attr_accessor :excluded_dirs
56
+
57
+ # Full final path where html reports will be generated
58
+ attr_reader :reports_path
59
+
60
+ # Optional. If true will generate index file but not launch processes. Used for testing.
61
+ attr_accessor :dry_run
47
62
 
48
63
  def initialize
49
64
  yield self if block_given?
@@ -57,15 +72,20 @@ module Multicuke
57
72
 
58
73
  def start
59
74
  FileUtils.mkdir_p reports_path
60
- index_file_path = File.join(reports_path, "index.html")
61
- index_file = File.new(index_file_path, "w")
75
+ launch_process_per_dir
76
+ collect_results
77
+ ReportsIndex.new(reports_path, features_dirs).generate
78
+ end
79
+
80
+ private
62
81
 
82
+ def launch_process_per_dir
63
83
  unless dry_run
64
84
  features_dirs.each { |features_dir|
65
85
  report_file_path = File.join(reports_path, "#{features_dir.name}.html")
66
- feature_full_path = File.join(features_dir_path, "#{features_dir.name}")
86
+ feature_full_path = File.join(features_root_path, "#{features_dir.name}")
67
87
  fork {
68
- command = "bundle exec cucumber #{feature_full_path} -r #{features_dir_path} --format html --out #{report_file_path}"
88
+ command = "bundle exec cucumber #{feature_full_path} -r #{features_root_path} --format html --out #{report_file_path}"
69
89
  p "RUNNING #{command}"
70
90
  system command
71
91
  }
@@ -73,7 +93,9 @@ module Multicuke
73
93
  p Process.waitall
74
94
  }
75
95
  end
96
+ end
76
97
 
98
+ def collect_results
77
99
  features_dirs.each { |features_dir|
78
100
  feature_file = File.join(reports_path, "#{features_dir.name}.html")
79
101
  File.open(feature_file) { |file|
@@ -92,42 +114,6 @@ module Multicuke
92
114
  features_dir.failed = failed
93
115
  } if File.exists?(feature_file)
94
116
  }
95
-
96
- b = Builder::XmlMarkup.new :target => index_file, :indent => 2
97
- b.html {
98
- b.head {
99
- b.title("Cucumber reports")
100
- b.style(css_content)
101
- }
102
- b.body {
103
- b.h2("Features")
104
- b.ul {
105
- features_dirs.each { |features_dir|
106
- b.li(:class => (features_dir.failed? ? "failed" : "success")) {
107
- b.a(features_dir.human_name, :href => "#{features_dir.name}.html")
108
- b.span("[#{features_dir.duration}]", :class => "duration")
109
- b.span("Scenarios: #{features_dir.scenarios_results}, Steps: #{features_dir.steps_results}", :class => "result")
110
- }
111
- }
112
- }
113
- }
114
- }
115
-
116
- index_file.close
117
- end
118
-
119
- private
120
-
121
- def css_content
122
- <<-CSS
123
- body {font-family: "Lucida Grande", Helvetica, sans-serif; margin: 2em 8em 2em 8em;}
124
- ul {list-style-type: square;}
125
- li {margin: 1em 0 1em 0;}
126
- li span {float: right; margin-left: 1em; padding: 0 0.3em;}
127
- li.failed span.result{background: #DC6E6E;}
128
- li.success span.result{background: #C1E799;}
129
- span.duration {color: #999999;}
130
- CSS
131
117
  end
132
118
 
133
119
  def match_excluded_dirs(path)
@@ -140,7 +126,7 @@ module Multicuke
140
126
 
141
127
  def find_features_dirs
142
128
  @features_dirs = []
143
- Dir.glob(File.join(features_dir_path, "*")).reject{ |path|
129
+ Dir.glob(File.join(features_root_path, "*")).reject{ |path|
144
130
  File.file?(path) || match_excluded_dirs(path)
145
131
  }.map { |feature_path|
146
132
  File.basename(feature_path)
@@ -1,3 +1,3 @@
1
1
  module Multicuke
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/dryrun_spec.rb CHANGED
@@ -10,7 +10,7 @@ module Multicuke
10
10
 
11
11
  it "generates index file in output folder" do
12
12
  runner = Multicuke::Runner.new do |r|
13
- r.features_dir_path = File.expand_path("../features", __FILE__)
13
+ r.features_root_path = File.expand_path("../features", __FILE__)
14
14
  r.output_dir_name = "cuke_reports"
15
15
  r.dry_run = true
16
16
  r.output_path = RESULTS_DIR_PATH
@@ -25,7 +25,7 @@ module Multicuke
25
25
 
26
26
  it "write link to each features on index file" do
27
27
  runner = Multicuke::Runner.new do |r|
28
- r.features_dir_path = File.expand_path("../features", __FILE__)
28
+ r.features_root_path = File.expand_path("../features", __FILE__)
29
29
  r.excluded_dirs = ["steps_definition"]
30
30
  r.dry_run = true
31
31
  r.output_path = RESULTS_DIR_PATH
data/spec/fork_spec.rb CHANGED
@@ -4,9 +4,13 @@ module Multicuke
4
4
 
5
5
  describe "Forking" do
6
6
 
7
+ before(:each) do
8
+ FileUtils.rm_r(Dir.glob("#{RESULTS_DIR_PATH}/*"), :force => true)
9
+ end
10
+
7
11
  it "generates test results files" do
8
12
  runner = Multicuke::Runner.new do |r|
9
- r.features_dir_path = File.expand_path("../features", __FILE__)
13
+ r.features_root_path = File.expand_path("../features", __FILE__)
10
14
  r.excluded_dirs = ["steps_definition"]
11
15
  r.output_path = RESULTS_DIR_PATH
12
16
  end
data/spec/runner_spec.rb CHANGED
@@ -5,18 +5,17 @@ module Multicuke
5
5
  describe Runner do
6
6
  it "initializes with provided configuration" do
7
7
  runner = Multicuke::Runner.new do |r|
8
- r.features_dir_path = "my_feature_path"
8
+ r.features_root_path = "my_feature_path"
9
9
  r.output_dir_name = "my_reports"
10
10
  r.output_path = "my_output_path"
11
11
  r.dry_run = true
12
12
  r.excluded_dirs = ["my_first_dir", "my_second_dir"]
13
13
  end
14
14
 
15
- runner.features_dir_path.should == "my_feature_path"
15
+ runner.features_root_path.should == "my_feature_path"
16
16
  runner.output_dir_name.should == "my_reports"
17
17
  runner.output_path.should == "my_output_path"
18
18
  runner.dry_run.should be_true
19
- runner.reports_path.should == "my_output_path/my_reports"
20
19
  runner.excluded_dirs.should include("my_first_dir", "my_second_dir")
21
20
  end
22
21
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multicuke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -23,6 +23,7 @@ files:
23
23
  - README.md
24
24
  - Rakefile
25
25
  - lib/multicuke.rb
26
+ - lib/multicuke/reports_index.rb
26
27
  - lib/multicuke/runner.rb
27
28
  - lib/multicuke/version.rb
28
29
  - multicuke.gemspec