macros4cuke 0.3.42 → 0.4.00

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.
Files changed (35) hide show
  1. checksums.yaml +8 -8
  2. data/.rubocop.yml +20 -3
  3. data/CHANGELOG.md +15 -1
  4. data/examples/i18n/fr/features/step_definitions/use_macro_steps.rb +1 -1
  5. data/features/demo06.feature +75 -75
  6. data/features/demo07.feature +15 -0
  7. data/features/support/env.rb +6 -0
  8. data/features/support/macro_support.rb +2 -2
  9. data/lib/macro_steps.rb +19 -2
  10. data/lib/macros4cuke/coll-walker-factory.rb +119 -0
  11. data/lib/macros4cuke/constants.rb +1 -1
  12. data/lib/macros4cuke/exceptions.rb +23 -1
  13. data/lib/macros4cuke/formatter/all-notifications.rb +30 -0
  14. data/lib/macros4cuke/formatter/to-gherkin.rb +80 -0
  15. data/lib/macros4cuke/formatter/to-null.rb +86 -0
  16. data/lib/macros4cuke/formatter/to-trace.rb +100 -0
  17. data/lib/macros4cuke/formatting-service.rb +74 -0
  18. data/lib/macros4cuke/macro-collection.rb +3 -3
  19. data/lib/macros4cuke/macro-step-support.rb +1 -1
  20. data/lib/macros4cuke/macro-step.rb +10 -26
  21. data/lib/macros4cuke/templating/engine.rb +74 -29
  22. data/spec/macros4cuke/coll-walker-factory_spec.rb +269 -0
  23. data/spec/macros4cuke/formatter/to-gherkin_spec.rb +129 -0
  24. data/spec/macros4cuke/formatter/to-null_spec.rb +62 -0
  25. data/spec/macros4cuke/formatter/to-trace_spec.rb +155 -0
  26. data/spec/macros4cuke/formatting-service_spec.rb +138 -0
  27. data/spec/macros4cuke/macro-collection_spec.rb +7 -4
  28. data/spec/macros4cuke/macro-step-support_spec.rb +41 -24
  29. data/spec/macros4cuke/macro-step_spec.rb +13 -6
  30. data/spec/macros4cuke/templating/engine_spec.rb +11 -7
  31. data/spec/macros4cuke/templating/placeholder_spec.rb +1 -1
  32. data/spec/macros4cuke/templating/section_spec.rb +3 -1
  33. data/spec/macros4cuke/use-sample-collection.rb +79 -0
  34. data/spec/spec_helper.rb +3 -0
  35. metadata +15 -2
@@ -9,7 +9,11 @@ module Macros4Cuke # Open this namespace to avoid module qualifier prefixes
9
9
 
10
10
  describe MacroCollection do
11
11
 
12
- let(:singleton) { MacroCollection.instance() }
12
+ let(:singleton) { MacroCollection.instance }
13
+
14
+ before(:all) do
15
+ MacroCollection.instance.clear
16
+ end
13
17
 
14
18
  context 'Initialization:' do
15
19
  it 'should be empty' do
@@ -45,7 +49,7 @@ SNIPPET
45
49
 
46
50
  it 'should return the rendition of a given macro-step' do
47
51
  phrase = '[enter my credentials]'
48
- input_values = [ ['userid', 'nobody'], ['password', 'no-secret'] ]
52
+ input_values = [ %w[userid nobody], %w[password no-secret] ]
49
53
  rendered = singleton.render_steps(phrase, input_values)
50
54
  expected = <<-SNIPPET
51
55
  Given I landed in the homepage
@@ -57,8 +61,7 @@ SNIPPET
57
61
  expect(rendered).to eq(expected)
58
62
  end
59
63
 
60
-
61
- end
64
+ end # context
62
65
 
63
66
  end # describe
64
67
 
@@ -3,7 +3,7 @@
3
3
  require_relative '../spec_helper'
4
4
 
5
5
  # The class under test
6
- require_relative '../../lib/macros4cuke/macro-step-support'
6
+ require_relative '../../lib/macros4cuke/macro-step-support'
7
7
 
8
8
 
9
9
  module Macros4Cuke # Open the module to avoid lengthy qualified names
@@ -11,60 +11,67 @@ module Macros4Cuke # Open the module to avoid lengthy qualified names
11
11
  # Class created just for testing purposes.
12
12
  class MyWorld
13
13
  include Macros4Cuke::MacroStepSupport
14
-
14
+
15
15
  # The list of encountered sub-steps
16
16
  attr_reader(:substeps)
17
-
18
- # Let's mimicks the behaviour of a Cucumber::RbSupport::RbWorld
17
+
18
+ # Let's mimicks the behaviour of a Cucumber::RbSupport::RbWorld
19
19
  def steps(substep_text)
20
- @substeps ||= {}
20
+ @substeps ||= []
21
21
  @substeps << substep_text
22
22
  end
23
-
24
-
23
+
24
+
25
25
  end # class
26
26
 
27
27
  describe MacroStepSupport do
28
28
  # Rule to build a custom world object
29
29
  let(:world) { MyWorld.new }
30
-
30
+
31
31
  let(:phrase1) { 'enter the credentials' }
32
-
32
+
33
33
  let(:m1_substeps) do
34
34
  ssteps = <<-SNIPPET
35
35
  Given I landed in the homepage
36
36
  When I click "Sign in"
37
37
  And I fill in "Username" with "<userid>"
38
38
  And I fill in "Password" with "<password>"
39
- And I click "Submit"
39
+ And I click "Submit"
40
40
  SNIPPET
41
41
  ssteps
42
- end
42
+ end
43
43
 
44
+ # Start from a clean situation
45
+ before(:all) do
46
+ MacroCollection.instance.clear
47
+ end
48
+
49
+
44
50
  context 'Defining macro(s):' do
45
51
  it 'should add valid new macro' do
46
52
  expect { world.add_macro phrase1, m1_substeps, true }.not_to raise_error
47
53
  end
48
-
54
+
49
55
  it 'should complain when entering the same macro again' do
50
56
  # Error case: trying to register another macro with same key/phrase.
57
+ error_type = Macros4Cuke::DuplicateMacroError
51
58
  msg = "A macro-step with phrase 'enter the credentials' already exist."
52
59
  expect { world.add_macro(phrase1, m1_substeps, true) }.to raise_error(
53
- Macros4Cuke::DuplicateMacroError, msg)
60
+ error_type, msg)
54
61
  end
55
-
62
+
56
63
  it 'should complain macro uses no table and phrase is parameterless' do
57
- # Error case: substeps have arguments,
64
+ # Error case: substeps have arguments,
58
65
  # but the macro has no mechanism to pass the needed data.
59
66
  phrase = 'fill in the credentials'
60
67
  msg = "The sub-step argument 'userid' does not appear in the phrase."
61
68
  expect { world.add_macro(phrase, m1_substeps, false) }.to raise_error(
62
- Macros4Cuke::UnreachableSubstepArgument, msg)
69
+ Macros4Cuke::UnreachableSubstepArgument, msg)
63
70
  end
64
71
  end # context
65
-
72
+
66
73
  context 'Invoking macro(s):' do
67
-
74
+
68
75
  it 'should complain when invoking an unknown macro-step' do
69
76
  phrase_unknown = 'dream of a perfect world'
70
77
  msg = "Unknown macro-step with phrase: 'dream of a perfect world'."
@@ -72,16 +79,26 @@ SNIPPET
72
79
  Macros4Cuke::UnknownMacroError, msg)
73
80
  end
74
81
 
75
- end # context
76
-
82
+ it "should call the 'steps' method with substeps and variables" do
83
+ # Notice that the call syntax can be used inside step definitions
84
+ world.invoke_macro(phrase1, [%w[userid nobody], %w[password none]])
85
+
86
+ # Check that the 'steps' method was indeed called with correct argument
87
+ param_assignments = { '<userid>' => 'nobody', '<password>' => 'none' }
88
+ expected_text = m1_substeps.gsub(/<\S+>/, param_assignments)
89
+ expect(world.substeps.first).to eq(expected_text)
90
+ end
91
+
92
+ end # context
93
+
77
94
  context 'Clearing macro(s):' do
78
-
95
+
79
96
  it 'should clear all macros' do
80
- expect { world.clear_macros() }.not_to raise_error
81
-
97
+ expect { world.clear_macros }.not_to raise_error
98
+
82
99
  # Control the post-condition
83
100
  expect(MacroCollection.instance.macro_steps).to be_empty
84
- end
101
+ end
85
102
 
86
103
  end # context
87
104
 
@@ -20,8 +20,8 @@ describe MacroStep do
20
20
  And I click "Submit"
21
21
  SNIPPET
22
22
 
23
- snippet
24
- end
23
+ snippet
24
+ end
25
25
 
26
26
  # Default instantiation rule
27
27
  subject { MacroStep.new(sample_phrase, sample_template, true) }
@@ -29,13 +29,17 @@ end
29
29
 
30
30
  context 'Creation & initialization:' do
31
31
  it 'should be created with a phrase, substeps and a table use indicator' do
32
- expect { MacroStep.new(sample_phrase, sample_template, true) }.not_to raise_error
32
+ phrase = sample_phrase
33
+ template = sample_template
34
+ expect { MacroStep.new(phrase, template, true) }.not_to raise_error
33
35
  end
34
36
 
35
37
 
36
- it 'should complain when a sub-step argument can never be assigned a value via the phrase' do
38
+ it 'should complain when a sub-step argument can never be assigned' do
39
+ phrase = sample_phrase
40
+ template = sample_template
37
41
  msg = "The sub-step argument 'password' does not appear in the phrase."
38
- expect { MacroStep.new(sample_phrase, sample_template, false) }.to raise_error(
42
+ expect { MacroStep.new(phrase, template, false) }.to raise_error(
39
43
  Macros4Cuke::UnreachableSubstepArgument, msg)
40
44
  end
41
45
 
@@ -47,7 +51,10 @@ end
47
51
  Macros4Cuke::UselessPhraseArgument, msg)
48
52
  end
49
53
 
50
-
54
+ it 'should know its phrase' do
55
+ expect(subject.phrase).to eq(sample_phrase)
56
+ end
57
+
51
58
  it 'should know its key' do
52
59
  expect(subject.key).to eq('enter_my_credentials_as_X_T')
53
60
  end
@@ -21,14 +21,15 @@ describe Engine do
21
21
  And I click "Sign in"
22
22
  SNIPPET
23
23
 
24
- source
25
- end
24
+ source
25
+ end
26
26
 
27
27
  # Template containing two conditional sections
28
28
  let(:sophisticated_template) do
29
29
  source = <<-SNIPPET
30
30
  When I fill in "firstname" with "<firstname>"
31
31
  And I fill in "lastname" with "<lastname>"
32
+ # Next line defines a comment
32
33
  <?address> And I fill in "address" with "<address>"</address>
33
34
  <?birthdate>
34
35
  And I fill in "birthdate" with "<birthdate>"
@@ -38,7 +39,7 @@ SNIPPET
38
39
  SNIPPET
39
40
 
40
41
  source
41
- end
42
+ end
42
43
 
43
44
 
44
45
 
@@ -207,7 +208,8 @@ SNIPPET
207
208
 
208
209
  it 'should complain when a placeholder is empty or blank' do
209
210
  text_w_empty_arg = sample_template.sub(/userid/, '')
210
- msg = %q(An empty or blank argument occurred in 'And I fill in "Username" with "<>"'.)
211
+ msg = 'An empty or blank argument occurred in ' +
212
+ %Q('And I fill in "Username" with "<>"'.)
211
213
  expect { Engine.new text_w_empty_arg }.to raise_error(
212
214
  Macros4Cuke::EmptyArgumentError, msg)
213
215
  end
@@ -240,7 +242,8 @@ SNIPPET
240
242
  it 'should complain when a closing tag is found without opening tag' do
241
243
  # Replacing an end of section tag by another...
242
244
  wrong_end = sophisticated_template.sub(/<\?birthdate>/, '</foobar>')
243
- msg = 'End of section</foobar> found while no corresponding section is open.'
245
+ msg = 'End of section</foobar> found' +
246
+ ' while no corresponding section is open.'
244
247
  expect { Engine.new wrong_end }.to raise_error(StandardError, msg)
245
248
  end
246
249
 
@@ -304,10 +307,11 @@ SNIPPET
304
307
  it 'should render conditional sections' do
305
308
  instance = Engine.new(sophisticated_template)
306
309
 
307
- locals = { 'firstname' => 'Anon',
310
+ locals = {
311
+ 'firstname' => 'Anon',
308
312
  'lastname' => 'Eemoos' ,
309
313
  'birthdate' => '1976-04-21'
310
- }
314
+ }
311
315
  rendered_text = instance.render(Object.new, locals)
312
316
  expected = <<-SNIPPET
313
317
  When I fill in "firstname" with "Anon"
@@ -1,4 +1,4 @@
1
- # File: section_spec.rb
1
+ # File: placeholder_spec.rb
2
2
 
3
3
  require_relative '../../spec_helper'
4
4
 
@@ -48,7 +48,7 @@ describe Section do
48
48
  expect(subject.children).to eq(sample_children)
49
49
  end
50
50
 
51
- it 'should know the name all child placeholders' do
51
+ it 'should know the name of all child placeholders' do
52
52
  # Case: simple flat list of children
53
53
  sample_children.each { |a_child| subject.add_child(a_child) }
54
54
  expect(subject.variables).to eq([ 'user' ])
@@ -56,6 +56,8 @@ describe Section do
56
56
  # Case: at least one child is a group
57
57
  parent = Section.new('son')
58
58
  [ subject,
59
+ Comment.new('# Simple step'),
60
+ EOLine.new,
59
61
  StaticText.new('Bye '),
60
62
  Placeholder.new('firstname'),
61
63
  EOLine.new
@@ -0,0 +1,79 @@
1
+ # File: sample-collection.rb
2
+ # Purpose: mix-in module with helper methods to build a sample
3
+ # collection of macro-steps.
4
+
5
+ require_relative '../../lib/macros4cuke/macro-collection'
6
+
7
+ module Macros4Cuke # Open this namespace to avoid module qualifier prefixes
8
+
9
+ # Mix-in module.
10
+ # Defines a set of methods that builds for testing purposes
11
+ # a sample collection of macro-steps.
12
+ module UseSampleCollection
13
+ # Phrase of first macro-step in the collection.
14
+ SamplePhrase1 = 'enter my credentials as <userid>'
15
+
16
+ # Sub-steps of the first macro-step in the collection.
17
+ SampleSubsteps1 = begin
18
+ snippet = <<-SNIPPET
19
+ Given I landed in the homepage
20
+ When I click "Sign in"
21
+ And I fill in "Username" with "<userid>"
22
+ And I fill in "Password" with "<password>"
23
+ And I click "Submit"
24
+ SNIPPET
25
+
26
+ snippet
27
+ end
28
+
29
+ # Phrase of second macro-step in the collection.
30
+ SamplePhrase2 = 'fill in the form with'
31
+
32
+ # Sub-steps of the second macro-step in the collection.
33
+ SampleSubsteps2 = begin
34
+ snippet = <<-SNIPPET
35
+ When I fill in "first_name" with "<firstname>"
36
+ And I fill in "last_name" with "<lastname>"
37
+ And I fill in "street_address" with "<street_address>"
38
+ And I fill in "zip" with "<postcode>"
39
+ And I fill in "city" with "<city>"
40
+ And I fill in "country" with "<country>"
41
+
42
+ # Let's assume that the e-mail field is optional.
43
+ # The step between the <?email>...<email> will be executed
44
+ # when the argument <email> has a value assigned to it.
45
+ <?email>
46
+ And I fill in "email" with "<email>"
47
+ </email>
48
+
49
+ # Let's also assume that comment is also optional
50
+ # See the slightly different syntax: the conditional section
51
+ # <?comment>...<comment> may fit in a single line
52
+ <?comment> And I fill in "comment" with "<comment>"</comment>
53
+ And I click "Save"
54
+ SNIPPET
55
+ snippet
56
+ end
57
+
58
+ # Helper. Stuff the macro collection with sample steps.
59
+ def fill_collection()
60
+ coll = MacroCollection.instance
61
+
62
+ coll.clear # Start from scratch: zap the existing macro-steps
63
+
64
+ coll.add_macro(SamplePhrase1, SampleSubsteps1, true)
65
+ coll.add_macro(SamplePhrase2, SampleSubsteps2, true)
66
+ end
67
+
68
+
69
+ # Helper. For convenience, provide a shorter name
70
+ # for the macro-step collection.
71
+ def macro_coll()
72
+ return MacroCollection.instance
73
+ end
74
+
75
+ end # module
76
+
77
+ end # module
78
+
79
+ # End of file
data/spec/spec_helper.rb CHANGED
@@ -12,6 +12,9 @@ RSpec.configure do |config|
12
12
  # Disable the `should` syntax...
13
13
  c.syntax = :expect
14
14
  end
15
+
16
+ # Display stack trace in case of failure
17
+ config.full_backtrace = true
15
18
  end
16
19
 
17
20
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macros4cuke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.42
4
+ version: 0.4.00
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitri Geshef
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-04 00:00:00.000000000 Z
11
+ date: 2013-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cucumber
@@ -102,8 +102,14 @@ files:
102
102
  - README.md
103
103
  - lib/macros4cuke.rb
104
104
  - lib/macro_steps.rb
105
+ - lib/macros4cuke/coll-walker-factory.rb
105
106
  - lib/macros4cuke/constants.rb
106
107
  - lib/macros4cuke/exceptions.rb
108
+ - lib/macros4cuke/formatter/all-notifications.rb
109
+ - lib/macros4cuke/formatter/to-gherkin.rb
110
+ - lib/macros4cuke/formatter/to-null.rb
111
+ - lib/macros4cuke/formatter/to-trace.rb
112
+ - lib/macros4cuke/formatting-service.rb
107
113
  - lib/macros4cuke/macro-collection.rb
108
114
  - lib/macros4cuke/macro-step-support.rb
109
115
  - lib/macros4cuke/macro-step.rb
@@ -127,16 +133,23 @@ files:
127
133
  - features/demo04.feature
128
134
  - features/demo05.feature
129
135
  - features/demo06.feature
136
+ - features/demo07.feature
130
137
  - features/step_definitions/demo_steps.rb
131
138
  - features/step_definitions/use_macro_steps.rb
132
139
  - features/support/env.rb
133
140
  - features/support/macro_support.rb
141
+ - spec/macros4cuke/coll-walker-factory_spec.rb
142
+ - spec/macros4cuke/formatter/to-gherkin_spec.rb
143
+ - spec/macros4cuke/formatter/to-null_spec.rb
144
+ - spec/macros4cuke/formatter/to-trace_spec.rb
145
+ - spec/macros4cuke/formatting-service_spec.rb
134
146
  - spec/macros4cuke/macro-collection_spec.rb
135
147
  - spec/macros4cuke/macro-step-support_spec.rb
136
148
  - spec/macros4cuke/macro-step_spec.rb
137
149
  - spec/macros4cuke/templating/engine_spec.rb
138
150
  - spec/macros4cuke/templating/placeholder_spec.rb
139
151
  - spec/macros4cuke/templating/section_spec.rb
152
+ - spec/macros4cuke/use-sample-collection.rb
140
153
  - spec/spec_helper.rb
141
154
  homepage: https://github.com/famished-tiger/Macros4Cuke
142
155
  licenses: