macros4cuke 0.3.12 → 0.3.13

Sign up to get free protection for your applications and to get access to all the features.
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AsciiComments:
2
+ Enabled: false
3
+
4
+ CaseIndentation:
5
+ Enabled: false
6
+
7
+ DefWithParentheses:
8
+ Enabled: false
9
+
10
+ EmptyLines:
11
+ Enabled: false
12
+
13
+
14
+ StringLiterals:
15
+ Enabled: false
16
+
17
+ TrailingWhitespace:
18
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.13 / 2013-05-14
2
+ * [NEW] File `.rubocop.yml` Added.
3
+ * [CHANGE] Many source files changed to please Rubocop.
4
+
1
5
  ## 0.3.12 / 2013-05-14
2
6
  * [NEW] File `.ruby-gemset` Added (for RVM users).
3
7
  * [NEW] File `.ruby-version` Added (for RVM users).
@@ -1,8 +1,11 @@
1
+ # encoding: utf-8
1
2
  # File: use_macro_steps.rb
2
- # Place a copy of this file in the feature/step_definitions folder of your own Cucumber-based project.
3
+ # Place a copy of this file in the feature/step_definitions folder
4
+ # of your own Cucumber-based project.
3
5
 
4
6
  # The following require will load the step definitions from Macros4Cuke.
5
- # This allows feature file authors to use macro steps in their Cucumber scenarios.
7
+ # This allows feature file authors to use macro steps
8
+ # in their Cucumber scenarios.
6
9
  require 'macros4cuke/../macro_steps'
7
10
 
8
11
  # End of file
@@ -1,4 +1,4 @@
1
- # encoding: utf-8 You should see a paragraph character: §
1
+ # encoding: utf-8
2
2
  # File: env.rb
3
3
 
4
4
 
@@ -1,7 +1,8 @@
1
- # encoding: utf-8 You should see a paragraph character: §
1
+ # encoding: utf-8
2
2
  # File: macro_support.rb
3
3
  # Purpose: Add the support for macros in Cucumber.
4
- # This file is meant to be put next to the 'env.rb' file of your Cucumeber project.
4
+ # This file is meant to be put next to the 'env.rb' file
5
+ # of your Cucumeber project.
5
6
 
6
7
 
7
8
  # Macros4Cuke step one: Load modules and classes from the gem.
@@ -9,18 +9,21 @@ end
9
9
 
10
10
 
11
11
  Quand(/^j(?:e |')\[((?:[^\\\]]|\\.)+)\]$/) do |macro_phrase|
12
- invoke_macro(macro_phrase) # This will call the macro with the given phrase
12
+ # This will call the macro with the given phrase
13
+ invoke_macro(macro_phrase)
13
14
  end
14
15
 
15
16
 
16
17
  Quand(/^j(?:e |')\[([^\]]+)\]:$/) do |macro_phrase, table_argument|
17
18
  # Ensure that the second argument is of the correct type
18
19
  unless table_argument.kind_of?(Cucumber::Ast::Table)
19
- raise Macros4Cuke::DataTableNotFound, "This step must have a data table as an argument."
20
+ error_message = "This step must have a data table as an argument."
21
+ raise Macros4Cuke::DataTableNotFound, error_message
20
22
  end
21
23
 
22
24
  # This will call the macro with the given phrase.
23
- # The second argument consists of an array with couples of the kind: [argument name, actual value]
25
+ # The second argument consists of an array with couples
26
+ # of the kind: [argument name, actual value]
24
27
  invoke_macro(macro_phrase, table_argument.raw)
25
28
  end
26
29
 
@@ -1,7 +1,8 @@
1
1
  # encoding: utf-8 You should see a paragraph character: §
2
2
  # File: macro_support.rb
3
3
  # Purpose: Add the support for macros in Cucumber.
4
- # This file is meant to be put next to the 'env.rb' file of your Cucumeber project.
4
+ # This file is meant to be put next to the 'env.rb' file
5
+ # of your Cucumeber project.
5
6
 
6
7
 
7
8
  # Macros4Cuke step one: Load modules and classes from the gem.
@@ -1,17 +1,18 @@
1
+ # encoding: utf-8
1
2
  # File: demo_steps.rb
2
3
  # A few step definitions for demo and testing purpose.
3
4
 
4
5
  When(/^I landed in the homepage$/) do
5
- trace_steps << %Q|Invoked step: ... I landed in the homepage|
6
+ trace_steps << 'Invoked step: ... I landed in the homepage'
6
7
  end
7
8
 
8
9
  When(/^I click "([^"]*)"$/) do |element|
9
- trace_steps << %Q|Invoked step: ... I click "#{element}"|
10
+ trace_steps << "Invoked step: ... I click \"#{element}\""
10
11
  end
11
12
 
12
13
 
13
14
  When(/^I fill in "(.*?)" with "(.*?)"$/) do |element, text|
14
- trace_steps << %Q|Invoked step: ... I fill in "#{element}" with "#{text}"|
15
+ trace_steps << "Invoked step: ... I fill in \"#{element}\" with \"#{text}\""
15
16
  end
16
17
 
17
18
 
@@ -1,8 +1,11 @@
1
+ # encoding: utf-8
1
2
  # File: use_macro_steps.rb
2
- # Place a copy of this file in the feature/step_definitions folder of your own Cucumber-based project.
3
+ # Place a copy of this file in the feature/step_definitions folder
4
+ # of your own Cucumber-based project.
3
5
 
4
6
  # The following require will load the step definitions from Macros4Cuke.
5
- # This allows feature file authors to use macro steps in their Cucumber scenarios.
7
+ # This allows feature file authors to use macro steps
8
+ # in their Cucumber scenarios.
6
9
  require 'macros4cuke/../macro_steps'
7
10
 
8
11
  # End of file
@@ -1,11 +1,13 @@
1
1
  # encoding: utf-8 You should see a paragraph character: §
2
2
  # File: env.rb
3
- # Purpose: Allow Cucumber to load the sample application configuration and hooks.
4
- # It also demonstrate what to do in your env.rb file to use the Macros4Cuke gem.
3
+ # Purpose: Allow Cucumber to load the sample application configuration
4
+ # and hooks.
5
+ # It also demonstrate what to do in your env.rb file
6
+ # to use the Macros4Cuke gem.
5
7
 
6
8
  begin
7
9
  require 'simplecov'
8
- rescue LoadError
10
+ rescue LoadError => exc
9
11
  # Gobble silently the exception if simplecov isn't installed.
10
12
  end
11
13
 
@@ -1,7 +1,8 @@
1
- # encoding: utf-8 You should see a paragraph character: §
1
+ # encoding: utf-8
2
2
  # File: macro_support.rb
3
3
  # Purpose: Add the support for macros in Cucumber.
4
- # This file is meant to be put next to the 'env.rb' file of your Cucumeber project.
4
+ # This file is meant to be put next to the 'env.rb' file
5
+ # of your Cucumeber project.
5
6
 
6
7
 
7
8
  # Macros4Cuke step one: Load modules and classes from the gem.
@@ -1,24 +1,27 @@
1
+ # encoding: utf-8
1
2
  # File: constants.rb
2
3
  # Purpose: definition of Macros4Cuke constants.
3
4
 
4
5
  module Macros4Cuke # Module used as a namespace
5
- # The version number of the gem.
6
- Version = '0.3.12'
6
+ # The version number of the gem.
7
+ Version = '0.3.13'
7
8
 
8
9
  # Brief description of the gem.
9
10
  Description = "Macros for Cucumber"
10
11
 
11
- # Constant Macros4Cuke::RootDir contains the absolute path of Rodent's root directory. Note: it also ends with a slash character.
12
- unless defined?(RootDir)
13
- # The initialisation of constant RootDir is guarded in order to avoid multiple initialisation (not allowed for constants)
12
+ # Constant Macros4Cuke::RootDir contains the absolute path of Rodent's
13
+ # root directory. Note: it also ends with a slash character.
14
+ unless defined?(RootDir)
15
+ # The initialisation of constant RootDir is guarded in order
16
+ # to avoid multiple initialisation (not allowed for constants)
14
17
 
15
18
  # The root folder of Macros4Cuke.
16
- RootDir = begin
19
+ RootDir = begin
17
20
  require 'pathname' # Load Pathname class from standard library
18
21
  rootdir = Pathname(__FILE__).dirname.parent.parent.expand_path()
19
22
  rootdir.to_s() + '/' # Append trailing slash character to it
20
23
  end
21
- end
24
+ end
22
25
  end # module
23
26
 
24
27
  # End of file
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  # File: macro-collection.rb
2
3
  # Purpose: Implementation of the MacroCollection class.
3
4
 
@@ -7,8 +8,9 @@ require_relative "macro-step"
7
8
  module Macros4Cuke # Module used as a namespace
8
9
 
9
10
  # Represents a container of macros.
10
- # It gathers all the macros encountered by Cucumber while "executing" the feature files.
11
- # @note This is a singleton class (i.e. there is only one macro collection object).
11
+ # It gathers all the macros encountered by Cucumber while "executing"
12
+ # the feature files.
13
+ # @note This is a singleton class: there is only one macro collection object.
12
14
  class MacroCollection
13
15
  include Singleton # Use the Singleton design pattern.
14
16
 
@@ -19,9 +21,11 @@ class MacroCollection
19
21
  public
20
22
  # Add a new macro.
21
23
  # Pre-condition: there is no existing macro with the same key.
22
- # @param aPhrase [String] The text that is enclosed between the square brackets.
24
+ # @param aPhrase [String] The text that is enclosed between
25
+ # the square brackets.
23
26
  # @param aTemplate [String] A text that consists of a sequence of sub-steps.
24
- # @param useTable [boolean] A flag indicating whether a table should be used to pass actual values.
27
+ # @param useTable [boolean] A flag indicating whether a table should be
28
+ # used to pass actual values.
25
29
  def add_macro(aPhrase, aTemplate, useTable)
26
30
  new_macro = MacroStep.new(aPhrase, aTemplate, useTable)
27
31
 
@@ -38,7 +42,8 @@ public
38
42
  # and (optionally) given a table of values.
39
43
  # Return the rendered steps as a text.
40
44
  # @param aPhrase [String] an instance of the macro phrase.
41
- # @param rawData [Array or nil] An Array with coupples of the form: [macro argument name, a value].
45
+ # @param rawData [Array or nil] An Array with coupples of the form:
46
+ # [macro argument name, a value].
42
47
  # Multiple rows with same argument name are acceptable.
43
48
  # @return [String]
44
49
  def render_steps(aPhrase, rawData = nil)
@@ -52,7 +57,8 @@ public
52
57
 
53
58
 
54
59
  # Clear/remove all macro definitions from the collection.
55
- # Post-condition: we are back to the same situation as no macro was ever defined.
60
+ # Post-condition: we are back to the same situation as
61
+ # no macro was ever defined.
56
62
  def clear()
57
63
  macro_steps.clear()
58
64
  end
@@ -67,7 +73,8 @@ public
67
73
  private
68
74
  # Retrieve the macro, given a phrase.
69
75
  def find_macro(aMacroPhrase, useTable)
70
- return macro_steps[MacroStep::macro_key(aMacroPhrase, useTable, :invokation)]
76
+ key = MacroStep.macro_key(aMacroPhrase, useTable, :invokation)
77
+ return macro_steps[key]
71
78
  end
72
79
 
73
80
  end # class
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  # File: macro-step-support.rb
2
3
 
3
4
  require_relative "exceptions"
@@ -10,28 +11,35 @@ module Macros4Cuke # Module used as a namespace
10
11
  #
11
12
  # require 'macros4cuke'
12
13
  # ...
13
- # World(Macros4Cuke::MacroStepSupport) # Extend the world object with this module.
14
+ # # Extend the world object with this module.
15
+ # World(Macros4Cuke::MacroStepSupport)
14
16
  #
15
17
  module MacroStepSupport
16
18
  public
17
19
 
18
20
  # Add a new macro.
19
21
  # Pre-condition: there is no existing macro with the same key.
20
- # @param aPhrase [String] The text that is enclosed between the square brackets [...].
21
- # @param aTemplate [String] The text template that consists of a sequence of sub-steps.
22
- # @param useTable [boolean] A flag that indicates whether a table should be used to pass actual values.
22
+ # @param aPhrase [String] The text that is enclosed between
23
+ # the square brackets [...].
24
+ # @param aTemplate [String] The text template that consists of a sequence
25
+ # of sub-steps.
26
+ # @param useTable [boolean] A flag that indicates whether a table should be
27
+ # used to pass actual values.
23
28
  def add_macro(aPhrase, aTemplate, useTable)
24
- MacroCollection::instance.add_macro(aPhrase, aTemplate, useTable)
29
+ MacroCollection.instance.add_macro(aPhrase, aTemplate, useTable)
25
30
  end
26
31
 
27
32
 
28
33
  # Invoke a macro with given phrase and (optionally) a table of values
29
- # @param aPhraseInstance [String] an instance of the macro phrase. That is, the text between [...] and with zero or more actual values.
30
- # @param rawData [Array or nil] An Array with coupples of the form: [macro argument name, a value].
34
+ # @param aPhraseInstance [String] an instance of the macro phrase.
35
+ # That is, the text between [...] and with zero or more actual values.
36
+ # @param rawData [Array or nil] An Array with coupples of the form:
37
+ # [macro argument name, a value].
31
38
  # Multiple rows with same argument name are acceptable.
32
39
  def invoke_macro(aPhraseInstance, rawData = nil)
33
40
  # Generate a text rendition of the step to be executed.
34
- rendered_steps = MacroCollection::instance.render_steps(aPhraseInstance, rawData)
41
+ collection = MacroCollection.instance()
42
+ rendered_steps = collection.render_steps(aPhraseInstance, rawData)
35
43
 
36
44
  # Let Cucumber execute the sub-steps
37
45
  steps(rendered_steps)
@@ -39,9 +47,10 @@ public
39
47
 
40
48
 
41
49
  # Clear (remove) all the macro-step definitions.
42
- # After this, we are in the same situation when no macro-step was ever defined.
50
+ # After this, we are in the same situation when no macro-step
51
+ # was ever defined.
43
52
  def clear_macros()
44
- MacroCollection::instance.clear()
53
+ MacroCollection.instance.clear()
45
54
  end
46
55
 
47
56
  end # module
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  # File: macro-step.rb
2
3
  # Purpose: Implementation of the MacroStep class.
3
4
 
@@ -99,7 +100,8 @@ class MacroStep
99
100
  # Render the steps from the template, given the values
100
101
  # taken by the parameters
101
102
  # @param aPhrase [String] an instance of the macro phrase.
102
- # @param rawData [Array or nil] An Array with coupples of the form: [macro argument name, a value].
103
+ # @param rawData [Array or nil] An Array with coupples of the form:
104
+ # [macro argument name, a value].
103
105
  # Multiple rows with same argument name are acceptable.
104
106
  def expand(aPhrase, rawData)
105
107
  params = validate_params(aPhrase, rawData)
@@ -109,7 +111,8 @@ class MacroStep
109
111
  private
110
112
  # Build a Hash from the given raw data.
111
113
  # @param aPhrase [String] an instance of the macro phrase.
112
- # @param rawData [Array or nil] An Array with coupples of the form: [macro argument name, a value].
114
+ # @param rawData [Array or nil] An Array with coupples of the form:
115
+ # [macro argument name, a value].
113
116
  # Multiple rows with same argument name are acceptable.
114
117
  def validate_params(aPhrase, rawData)
115
118
  macro_parameters = {}
@@ -169,28 +172,35 @@ private
169
172
  end
170
173
 
171
174
  # Return the substeps text after some transformation
172
- # [theSubstepsSource] The source text of the steps to be expanded upon macro invokation.
175
+ # [theSubstepsSource] The source text of the steps
176
+ # to be expanded upon macro invokation.
173
177
  def preprocess(theSubstepsSource)
174
178
  # Split text into lines
175
179
  lines = theSubstepsSource.split(/\r\n?|\n/)
176
180
 
177
- # Reject comment lines. This necessary because Cucumber::RbSupport::RbWorld#steps complains when it sees a comment.
181
+ # Reject comment lines. This is necessary because
182
+ # Cucumber::RbSupport::RbWorld#steps complains when it sees a comment.
178
183
  processed = lines.reject { |a_line| a_line =~ /\s*#/ }
179
184
 
180
185
  return processed.join("\n")
181
186
  end
182
187
 
183
- # Check for inconsistencies between the argument names in the phrase and the substeps part.
188
+ # Check for inconsistencies between the argument names
189
+ # in the phrase and the substeps part.
184
190
  def validate_phrase_args(thePhraseArgs, substepsVars)
185
191
  # Error when the phrase names an argument that never occurs in the substeps
186
192
  thePhraseArgs.each do |phrase_arg|
187
- raise UselessPhraseArgument.new(phrase_arg) unless substepsVars.include? phrase_arg
188
- end
189
-
190
- # Error when a substep has an argument that never appears in the phrase and the macro-step does not use data table.
193
+ unless substepsVars.include? phrase_arg
194
+ raise UselessPhraseArgument.new(phrase_arg)
195
+ end
196
+ end
197
+ # Error when a substep has an argument that never appears in the phrase
198
+ # and the macro-step does not use data table.
191
199
  unless use_table?
192
200
  substepsVars.each do |substep_arg|
193
- raise UnreachableSubstepArgument.new(substep_arg) unless thePhraseArgs.include? substep_arg
201
+ unless thePhraseArgs.include? substep_arg
202
+ raise UnreachableSubstepArgument.new(substep_arg)
203
+ end
194
204
  end
195
205
  end
196
206
 
@@ -198,7 +208,8 @@ private
198
208
  end
199
209
 
200
210
 
201
- # Return true, if the macro-step requires a data table to pass actual values of the arguments.
211
+ # Return true, if the macro-step requires a data table
212
+ # to pass actual values of the arguments.
202
213
  def use_table?()
203
214
  return key =~ /_T$/
204
215
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  # File: engine.rb
2
3
  # Purpose: Implementation of the MacroStep class.
3
4
 
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  # File: spec_helper.rb
2
3
  # Purpose: utility file that is loaded by all our RSpec files
3
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: macros4cuke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.12
4
+ version: 0.3.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-17 00:00:00.000000000 Z
12
+ date: 2013-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
@@ -81,6 +81,7 @@ executables: []
81
81
  extensions: []
82
82
  extra_rdoc_files: []
83
83
  files:
84
+ - .rubocop.yml
84
85
  - .rspec
85
86
  - .ruby-gemset
86
87
  - .ruby-version