stepdown 0.1 → 0.2

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.
data/.rspec ADDED
File without changes
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
3
  gem 'haml'
4
- gem 'rspec'
4
+
5
+ group :development,:test do
6
+ gem 'rspec'
7
+ end
data/bin/stepdown CHANGED
@@ -4,9 +4,26 @@ $:.unshift lib unless $:.include?(lib)
4
4
 
5
5
  require 'step_down'
6
6
 
7
+ def show_help
8
+ puts "Usage: stepdown step_definition_dir feature_file_directory"
9
+ puts "eg. stepdown ./features/step_definitions/ ./features/"
10
+ end
11
+
7
12
  begin
8
- StepDown.new(ARGV[0], ARGV[1]).analyse
13
+
14
+ if ARGV[0] =~ /(-h|--help)/ || ARGV.length != 2
15
+ show_help
16
+ exit
17
+ end
18
+
19
+ if ARGV.length <=> 2
20
+ default_path = Dir.pwd
21
+ StepDown.new(default_path + "/features/step_definitions", default_path + "/features").analyse
22
+ else
23
+ StepDown.new(ARGV[0], ARGV[1]).analyse
24
+ end
9
25
  rescue Interrupt => e
10
26
  puts "Quiting..."
11
27
  exit 1
12
28
  end
29
+
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/step')
2
+ class CountingStep < Step
3
+ attr_accessor :count
4
+
5
+ def initialize(id, regex)
6
+ @count = 0
7
+ super(id, regex)
8
+ end
9
+
10
+ def <=>(step)
11
+ self.count <=> step.count
12
+ end
13
+
14
+ end
data/lib/step_group.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'cgi'
2
+ require 'counting_step'
2
3
  class StepGroup
3
- attr_reader :id, :regex, :in_steps, :total_usage
4
+ attr_reader :id, :regex, :total_usage
4
5
 
5
6
  def initialize(step)
6
7
  @id = step.id
@@ -10,16 +11,15 @@ class StepGroup
10
11
  end
11
12
 
12
13
  def in_steps
13
- @in_steps.sort{|a,b| b[0] <=> a[0] }
14
+ @in_steps.sort{|a,b| b[1] <=> a[1]}
14
15
  end
15
16
 
16
17
  def add_step(step)
17
18
  if @in_steps[step.id]
18
- @in_steps[step.id][:count] += 1
19
+ @in_steps[step.id].count += 1
19
20
  else
20
- @in_steps[step.id] = {}
21
- @in_steps[step.id][:count] = 1
22
- @in_steps[step.id][:step] = step
21
+ @in_steps[step.id] = CountingStep.new(step.id, step.regex)
22
+ @in_steps[step.id].count = 1
23
23
  end
24
24
  end
25
25
 
@@ -27,7 +27,7 @@ class StepGroup
27
27
  @total_usage = 0
28
28
  #puts step[:in_steps].inspect
29
29
  @in_steps.each do |key,val|
30
- @total_usage += val[:count]
30
+ @total_usage += val.count
31
31
  end
32
32
  @total_usage
33
33
  end
@@ -0,0 +1,119 @@
1
+ require 'rspec'
2
+ require File.expand_path(File.dirname(__FILE__) + '/../../lib/step_group')
3
+ require File.expand_path(File.dirname(__FILE__) + '/../../lib/counting_step')
4
+ require File.expand_path(File.dirname(__FILE__) + '/../../lib/step')
5
+
6
+ describe StepGroup do
7
+
8
+ describe "returning the number of steps that are near the current step" do
9
+ before :each do
10
+ @step_group = StepGroup.new(Step.new(0,/regex/))
11
+ end
12
+
13
+ it "should return an empty hash when for an empty group" do
14
+ @step_group.in_steps.should be_empty
15
+ end
16
+
17
+ it "should return the current steps in the group" do
18
+ @step_group.add_step(Step.new(1,/regex/))
19
+ @step_group.add_step(Step.new(2,/regex/))
20
+ @step_group.add_step(Step.new(3,/regex/))
21
+
22
+ @step_group.in_steps.count.should == 3
23
+ end
24
+
25
+ it "should return the steps ordered by use count" do
26
+ @step_group.add_step(Step.new(1,/regex/))
27
+ @step_group.add_step(Step.new(1,/regex/))
28
+ @step_group.add_step(Step.new(3,/regex/))
29
+ @step_group.add_step(Step.new(3,/regex/))
30
+ @step_group.add_step(Step.new(3,/regex/))
31
+ @step_group.add_step(Step.new(2,/regex/))
32
+
33
+ @step_group.in_steps[0][1].count.should == 3
34
+ @step_group.in_steps[1][1].count.should == 2
35
+ @step_group.in_steps[2][1].count.should == 1
36
+ end
37
+
38
+ end
39
+
40
+ describe "adding a step to the step group" do
41
+ before :each do
42
+ @step_group = StepGroup.new(Step.new(0,/regex/))
43
+ end
44
+
45
+ it "should add new steps" do
46
+ step1 = Step.new(1,/regex/)
47
+ counting_step = mock("counting_step")
48
+ CountingStep.stub!(:new).and_return(counting_step)
49
+ counting_step.should_receive(:count=).with(1)
50
+ @step_group.add_step(step1)
51
+ @step_group.in_steps.should == [[1, counting_step]]
52
+
53
+ end
54
+
55
+ it "should update the count for an existing step" do
56
+
57
+ step1 = Step.new(1,/regex/)
58
+ @step_group.add_step(step1)
59
+ @step_group.add_step(step1)
60
+
61
+ @step_group.in_steps[0][1].count.should == 2
62
+ end
63
+
64
+ it "should update step counts when multiple steps present" do
65
+ step1 = Step.new(1,/regex/)
66
+ @step_group.add_step(step1)
67
+ @step_group.add_step(step1)
68
+
69
+ step2 = Step.new(2,/regex/)
70
+ @step_group.add_step(step2)
71
+
72
+ step3 = Step.new(3,/regex/)
73
+ @step_group.add_step(step3)
74
+ @step_group.add_step(step3)
75
+ @step_group.add_step(step3)
76
+
77
+ @step_group.in_steps[0][1].count.should == 3
78
+ @step_group.in_steps[1][1].count.should == 2
79
+ @step_group.in_steps[2][1].count.should == 1
80
+
81
+ end
82
+
83
+ end
84
+
85
+ describe "updating the use count of the main step" do
86
+ before :each do
87
+ @step_group = StepGroup.new(Step.new(0,/regex/))
88
+ end
89
+
90
+ it "should return 0 for an empty group" do
91
+ @step_group.update_use_count.should be_zero
92
+ end
93
+
94
+ it "should return the total use" do
95
+ @step_group.add_step(Step.new(1,/regex/))
96
+ @step_group.add_step(Step.new(1,/regex/))
97
+ @step_group.add_step(Step.new(3,/regex/))
98
+ @step_group.add_step(Step.new(4,/regex/))
99
+ @step_group.add_step(Step.new(1,/regex/))
100
+
101
+ @step_group.update_use_count.should == 5
102
+ end
103
+
104
+ it "should update the use when new steps are added" do
105
+ @step_group.add_step(Step.new(1,/regex/))
106
+ @step_group.add_step(Step.new(1,/regex/))
107
+
108
+ @step_group.update_use_count.should == 2
109
+
110
+ @step_group.add_step(Step.new(3,/regex/))
111
+ @step_group.add_step(Step.new(4,/regex/))
112
+ @step_group.add_step(Step.new(1,/regex/))
113
+
114
+ @step_group.update_use_count.should == 5
115
+ end
116
+
117
+ end
118
+
119
+ end
data/stepdown.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "stepdown"
4
- s.version = "0.1"
4
+ s.version = "0.2"
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.authors = "Sean Caffery"
7
7
  s.email = "sean@lineonpoint.com"
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stepdown
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- version: "0.1"
8
+ - 2
9
+ version: "0.2"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sean Caffery
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-17 00:00:00 +11:00
17
+ date: 2011-02-15 00:00:00 +11:00
18
18
  default_executable: stepdown
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -43,10 +43,12 @@ extra_rdoc_files: []
43
43
 
44
44
  files:
45
45
  - .gitignore
46
+ - .rspec
46
47
  - Gemfile
47
48
  - Gemfile.lock
48
49
  - README.rdoc
49
50
  - bin/stepdown
51
+ - lib/counting_step.rb
50
52
  - lib/feature_parser.rb
51
53
  - lib/html_reporter.rb
52
54
  - lib/scenario.rb
@@ -57,6 +59,7 @@ files:
57
59
  - lib/step_usage.rb
58
60
  - public/jquery-1.4.3.min.js
59
61
  - public/step_down.js
62
+ - spec/lib/step_group_spec.rb
60
63
  - stepdown.gemspec
61
64
  - templates/main.html.haml
62
65
  - templates/style.sass