step_master 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,6 +38,11 @@ module StepMaster
38
38
  # matcher << "Given /^this is a step$/ do"
39
39
  #
40
40
  def <<(value)
41
+ add(value, :format => :rb)
42
+ end
43
+
44
+ def add(value, options = {})
45
+
41
46
  raise "#{value.inspect} is not a step" unless value =~ STEP_REGEX
42
47
 
43
48
  full_line = $&
@@ -65,7 +70,7 @@ module StepMaster
65
70
  regex.scan(CHUNK_REGEX).unshift(" ").unshift(step_type).collect { |i| StepItem.new(i, regex_options) }
66
71
  end
67
72
 
68
- elements.inject(@match_table) { |parent, i| parent[i] ||= Possible.new }.terminal!(value)
73
+ elements.inject(@match_table) { |parent, i| parent[i] ||= Possible.new }.terminal!(value, options)
69
74
  end
70
75
 
71
76
  # Returns all possible outcomes of a string.
@@ -94,8 +99,13 @@ module StepMaster
94
99
  end
95
100
 
96
101
  def where_is?(string)
97
- find_possible(string).select{ |x| x.terminal? }.collect { |x| x.result }
98
- end
102
+ find_possible(string).select{ |x| x.terminal? }.collect { |x| x.file || x.result }
103
+ end
104
+
105
+ def terminals(string)
106
+ find_possible(string).select{ |x| x.terminal? }
107
+ end
108
+
99
109
 
100
110
  private
101
111
  def find_possible(input, against = @match_table)
@@ -2,20 +2,27 @@ module StepMaster
2
2
  class Possible < ::Hash
3
3
  EMPTY = Possible.new
4
4
 
5
- def terminal!(result)
6
- @terminal = result.freeze
5
+ attr_reader :file_path, :line_number
6
+
7
+ def terminal!(result, options = {})
8
+ @terminal = true
9
+ @result = result
10
+ @file_path = options[:file_path].freeze
11
+ @line_number = options[:line_number].freeze
7
12
  end
8
13
 
9
14
  def terminal?
10
- !@terminal.nil?
15
+ @terminal
11
16
  end
12
17
 
13
18
  def result
14
- @terminal
19
+ @result
15
20
  end
16
21
 
17
- def inspect
18
- super << ((terminal? )? "["+result+"]" : "")
22
+ def file
23
+ if @file_path
24
+ [@file_path, @line_number].compact.join(":")
25
+ end
19
26
  end
20
27
  end
21
28
  end
data/lib/step_master.rb CHANGED
@@ -4,5 +4,5 @@ $:.unshift(File.dirname(__FILE__)) unless
4
4
  require 'step_master/matcher'
5
5
 
6
6
  module StepMaster
7
- VERSION = '0.0.3'
7
+ VERSION = '0.0.4'
8
8
  end
@@ -27,6 +27,40 @@ module StepMaster
27
27
  end
28
28
  end
29
29
 
30
+
31
+
32
+ describe "#add()" do
33
+ it "accepts a string" do
34
+ @matcher.add(VALID_STEP)
35
+ end
36
+
37
+ it "should not like a step it can't parse" do
38
+ lambda {
39
+ @matcher.add "This is not a step"
40
+ }.should raise_error(%q["This is not a step" is not a step])
41
+ end
42
+
43
+ describe "accepts optional paramters" do
44
+ it "should accept :file_path with just a file name" do
45
+ @matcher.add(VALID_STEP, :file_path => "step.rb")
46
+ end
47
+
48
+ it "should accept :file_path an entire path" do
49
+ @matcher.add(VALID_STEP, :file_path => "/src/project/step.rb")
50
+ end
51
+
52
+ it "should accept :file_path and :line_number" do
53
+ @matcher.add(VALID_STEP, :file_path => "/src/project/step.rb", :line_number => 6)
54
+ end
55
+
56
+ it "should accept :format" do
57
+ @matcher.add(VALID_STEP, :format => :rb)
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+
30
64
  describe "#is_match?" do
31
65
 
32
66
  describe "with a terminal and longer step" do
@@ -305,17 +339,40 @@ module StepMaster
305
339
  end
306
340
 
307
341
  end
342
+
308
343
  describe "#where_is?" do
309
344
  describe "with step with a comment" do
310
345
  before :each do
311
- @matcher << %q~Given /^this$/i do |name| # This is a comment~
346
+ @matcher << %q~Given /^this$/i do # This is a comment~
312
347
  end
313
348
 
314
349
  it "should return the original line with where_is?" do
315
- @matcher.where_is?("Given this").should include(%q~Given /^this$/i do |name| # This is a comment~)
350
+ @matcher.where_is?("Given this").should include(%q~Given /^this$/i do # This is a comment~)
316
351
  end
317
352
  end
353
+
354
+ describe "with step with a file path" do
355
+ before :each do
356
+ @matcher.add(%q~Given /^this$/i do~, :file_path => "/src/test.rb")
357
+ end
358
+
359
+ it "should return the original line with where_is?" do
360
+ @matcher.where_is?("Given this").should include(%q~/src/test.rb~)
361
+ end
362
+ end
363
+
364
+ describe "with step with a file path and line_number" do
365
+ before :each do
366
+ @matcher.add(%q~Given /^this$/i do ~, :file_path => "/src/test.rb", :line_number => 6)
367
+ end
368
+
369
+ it "should return the original line with where_is?" do
370
+ @matcher.where_is?("Given this").should include(%q~/src/test.rb:6~)
371
+ end
372
+ end
373
+
318
374
  end
375
+
319
376
  end
320
377
 
321
378
  describe Matcher do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: step_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Holmes
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-16 00:00:00 -04:00
12
+ date: 2009-10-20 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency