macros4cuke 0.4.09 → 0.5.03
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +2 -2
- data/CHANGELOG.md +17 -0
- data/README.md +41 -22
- data/bin/macros4cuke +15 -0
- data/examples/demo/features/support/use_macros4cuke.rb +12 -0
- data/examples/i18n/fr/features/demo01-fr.feature +13 -0
- data/examples/i18n/fr/features/step_definitions/demo_steps.rb +5 -0
- data/examples/i18n/fr/features/step_definitions/{use_macro_steps.rb → macro_steps_fr.rb} +3 -2
- data/examples/i18n/fr/features/support/use_macros4cuke.rb +12 -0
- data/examples/i18n/nl/cucumber.yml +6 -0
- data/examples/i18n/nl/features/demo01-nl.feature +40 -0
- data/examples/i18n/nl/features/step_definitions/demo_steps.rb +21 -0
- data/examples/i18n/nl/features/step_definitions/macro_steps_nl.rb +31 -0
- data/examples/i18n/nl/features/support/use_macros4cuke.rb +12 -0
- data/features/support/use_macros4cuke.rb +11 -0
- data/lib/macros4cuke.rb +1 -0
- data/lib/macros4cuke/application.rb +75 -0
- data/lib/macros4cuke/cli/cmd-line.rb +142 -0
- data/lib/macros4cuke/constants.rb +2 -2
- data/lib/macros4cuke/cucumber.rb +16 -0
- data/lib/macros4cuke/exceptions.rb +25 -1
- data/lib/macros4cuke/templating/comment.rb +43 -0
- data/lib/macros4cuke/templating/eo-line.rb +30 -0
- data/lib/macros4cuke/templating/static-text.rb +40 -0
- data/lib/macros4cuke/templating/template-element.rb +7 -88
- data/spec/macros4cuke/application_spec.rb +117 -0
- data/spec/macros4cuke/cli/cmd-line_spec.rb +223 -0
- data/spec/macros4cuke/macro-collection_spec.rb +1 -1
- data/spec/macros4cuke/macro-step-support_spec.rb +1 -1
- data/spec/macros4cuke/templating/comment_spec.rb +1 -1
- data/spec/macros4cuke/templating/eo-line_spec.rb +2 -2
- data/spec/macros4cuke/templating/static_text_spec.rb +1 -1
- data/templates/use_macros4cuke.erb +12 -0
- metadata +35 -19
- data/examples/demo/features/step_definitions/use_macro_steps.rb +0 -10
- data/examples/demo/features/support/macro_support.rb +0 -16
- data/examples/i18n/fr/features/support/macro_support.rb +0 -17
- data/features/step_definitions/use_macro_steps.rb +0 -10
- data/features/support/macro_support.rb +0 -16
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTA1NWJhMjkxZGJhMjA3MTExOTNkOTEyYmYzNWNhYjJkYjkxYTllNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODRlMTdiNDAyM2JhMTUwNmU0ZjVmZjcwOTBhYjY3MDA0NDhkMzQwNg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODAzYWYyNWYzNGFlOTA2N2NmYzBlYmZkZWIwZWE2NTI2M2YyMmJiNjA2MzQx
|
10
|
+
NzhlMGVhNDg4NzBjOGE3YThkYTRhMTExNjZlNzZlMzA2Y2IxODQ0ZGY5MTIy
|
11
|
+
ZjBiNjhkMWVhYzAxNjU0MGRkNGFiMGMwYWMwNmEwY2IzZTExOTY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTY1MTE5MzM3OTQ1MmIyMzg5ZjU4ZTJmYzM5ODM3YzU1MmRkZTRkZGZlNWUy
|
14
|
+
ZjczOGExNTA3NDg3MzY2NWJlYzMxNjE4ZGRiYzY3ZmU2YzA4OGE1OWNjZTA3
|
15
|
+
ZDBkOGI5Y2YwZjZmZmY3MTExMTY2YTdjMjNjYTU2ODBlMWMxMGY=
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
### 0.5.03 / 2014-04-01
|
2
|
+
* [CHANGE] File `README.md`: Updated the installation steps.
|
3
|
+
* [CHANGE] Files `macro_support.rb` renamed to `use_macros4cuke.rb`
|
4
|
+
|
5
|
+
### 0.5.02 / 2014-03-31
|
6
|
+
* [CHANGE] File `.travis.yml`: Allow build failure with Travis' jruby-head (Travis build scripts miss Bundler install)
|
7
|
+
|
8
|
+
### 0.5.01 / 2014-03-31
|
9
|
+
* [CHANGE] File `macros4cuke`: Removal of command-line option echoing.
|
10
|
+
|
11
|
+
### 0.5.00 / 2014-03-31
|
12
|
+
* [NEW] Added macros4cuke "executable". The CLI simplifies the installation of macros in Cucumber projects.
|
13
|
+
* [NEW] File `cucumber.rb`: require only this file in order to integrate `Macros4Cuke` in your Cucumber project.
|
14
|
+
* [CHANGE] File `macros4cuke.gemspec`: Added `bin` and `templates` dirs.
|
15
|
+
* [NEW] File `exceptions.rb`: New command-line related exception classes.
|
16
|
+
|
17
|
+
|
1
18
|
### 0.4.09 / 2014-03-13
|
2
19
|
* [CHANGE] Updated source files to comply to Rubocop 0.19.
|
3
20
|
* [CHANGE] File `.rubocop.yml`: Disabled FileName cop.
|
data/README.md
CHANGED
@@ -73,39 +73,58 @@ Nicely formatted documentation extracted from these feature files is also availa
|
|
73
73
|
|
74
74
|
## Setup ##
|
75
75
|
### Pre-requisites ###
|
76
|
+
|
76
77
|
Macros4Cuke works with:
|
77
|
-
- MRI Ruby 1.9.x and 2.
|
78
|
-
- JRuby (was tested with version 1.7.3 and above)
|
78
|
+
- MRI Ruby 1.9.x, 2.0.x and 2.1.x.
|
79
|
+
- JRuby (was tested with version 1.7.3 and above),
|
80
|
+
- Rubinius 2.x
|
81
|
+
|
82
|
+
Macros4Cuke requires Cucumber.
|
79
83
|
|
80
84
|
### Installation ###
|
81
|
-
The macros4cuke gem is fairly standard
|
85
|
+
The macros4cuke gem installation is fairly standard.
|
86
|
+
If you have a `Gemfile`, add `macros4cuke` to it. Otherwise, install the gem like this:
|
87
|
+
|
82
88
|
```bash
|
83
89
|
$[sudo] gem install macros4cuke
|
84
90
|
```
|
85
91
|
|
86
|
-
### Configuring
|
87
|
-
|
88
|
-
|
89
|
-
|
92
|
+
### Configuring your Cucumber projects ####
|
93
|
+
The procedure to add support for macros in an existing Cucumber project
|
94
|
+
was simplified since version 0.5.00.
|
95
|
+
|
96
|
+
There are two possible ways to do it:
|
97
|
+
- By editing manually a support file; or,
|
98
|
+
- Let Macros4cuke configure your project.
|
99
|
+
|
100
|
+
#### Alternative 1: manually add one line in a support file
|
101
|
+
Require the library in one of your ruby files under `features/support` (e.g. `env.rb`):
|
102
|
+
|
90
103
|
```ruby
|
91
104
|
# /features/support/env.rb
|
92
|
-
# Add the
|
93
|
-
require 'macros4cuke'
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
* Step 2: Import the macro-management steps
|
98
|
-
In your `/features/step_definitions/` folder:
|
99
|
-
- The cleanest is to create a Ruby file (say, 'use\_macro\_steps.rb') with the line:
|
100
|
-
|
101
|
-
```ruby
|
102
|
-
require 'macros4cuke/../macro_steps'
|
103
|
-
```
|
104
|
-
- Alternatively, you could directly add the require in one of your step definition file.
|
105
|
-
|
106
|
-
|
105
|
+
# Add the next single line
|
106
|
+
require 'macros4cuke/cucumber'
|
107
|
+
```
|
108
|
+
|
107
109
|
That's it! Now you can start writing macros in your Cucumber project.
|
108
110
|
|
111
|
+
#### Alternative 2: let macros4cuke configure your project
|
112
|
+
|
113
|
+
Use the following command-line:
|
114
|
+
```bash
|
115
|
+
$[sudo] macros4cuke --setup project_path
|
116
|
+
```
|
117
|
+
|
118
|
+
Where __project_path__ is the location of your Cucumber project.
|
119
|
+
In case the working directory of the shell/command prompt is
|
120
|
+
already the directory containing the Cucumber project, then the
|
121
|
+
command-line is simply:
|
122
|
+
```bash
|
123
|
+
$[sudo] macros4cuke --setup .
|
124
|
+
```
|
125
|
+
|
126
|
+
Notice that ending dot above means "the current directory".
|
127
|
+
|
109
128
|
|
110
129
|
## Getting started ##
|
111
130
|
Working with a macro-step is a two-stages process:
|
data/bin/macros4cuke
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: macros4cuke
|
3
|
+
# The 'executable' of the Macros4Cuke library.
|
4
|
+
|
5
|
+
mydir = File.dirname(__FILE__)
|
6
|
+
lib_dir = mydir + '/../lib'
|
7
|
+
$LOAD_PATH.unshift lib_dir unless $LOAD_PATH.include?(lib_dir)
|
8
|
+
|
9
|
+
require 'macros4cuke' # Load the Cukedep::Application class
|
10
|
+
|
11
|
+
# The application's entry point
|
12
|
+
app = Macros4Cuke::Application.new
|
13
|
+
app.run!(ARGV.dup)
|
14
|
+
|
15
|
+
# End of file
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8 You should see a paragraph character: §
|
2
|
+
# File: use_macros4cuke.rb
|
3
|
+
# Purpose: Add the support for macros in Cucumber.
|
4
|
+
# This file is meant to be put next to the 'env.rb' file
|
5
|
+
# of your Cucumber project.
|
6
|
+
|
7
|
+
|
8
|
+
# Load modules, classes and step definitions from the macros4cuke gem
|
9
|
+
require 'macros4cuke/cucumber'
|
10
|
+
|
11
|
+
|
12
|
+
# End of file
|
@@ -3,6 +3,7 @@ Fonctionnalité: Macro-pas
|
|
3
3
|
Afin d'écrire des scénarios plus facilement
|
4
4
|
En tant qu'utilisateur de Cucumber
|
5
5
|
Je souhaite pouvoir créer des macro-étapes
|
6
|
+
|
6
7
|
|
7
8
|
Scénario: Définition d'un macro-pas (de scénario)
|
8
9
|
Etant donné que je crée le pas "Quand j'[imprime le texte <un_texte>]" qui équivaut à:
|
@@ -13,6 +14,11 @@ Scénario: Définition d'un macro-pas (de scénario)
|
|
13
14
|
|
14
15
|
Scénario: Utilisation d'un macro-pas (de scénario)
|
15
16
|
Quand j'[imprime le texte "Bonjour!"]
|
17
|
+
Alors je m'attends à voir:
|
18
|
+
"""
|
19
|
+
Bonjour!
|
20
|
+
|
21
|
+
"""
|
16
22
|
|
17
23
|
Scénario: Définition d'un macro-pas appelant des macro-pas!
|
18
24
|
Etant donné que je crée le pas "Quand j'[imprime le texte <un_texte> trois fois]" qui équivaut à:
|
@@ -24,4 +30,11 @@ Scénario: Définition d'un macro-pas appelant des macro-pas!
|
|
24
30
|
|
25
31
|
Scénario: Utilisation du dernier macro-pas (de scénario)
|
26
32
|
Quand j'[imprime le texte "Trois fois!" trois fois]
|
33
|
+
Alors je m'attends à voir:
|
34
|
+
"""
|
35
|
+
Trois fois!
|
36
|
+
Trois fois!
|
37
|
+
Trois fois!
|
38
|
+
|
39
|
+
"""
|
27
40
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# Quelques définitions de pas de scénarios Cucumber.
|
3
|
+
|
3
4
|
require 'stringio'
|
4
5
|
|
5
6
|
Quand(/^j'imprime "(.*?)" à l'écran$/) do |some_text|
|
@@ -11,4 +12,8 @@ Quand(/^je garde "(.*?)" en mémoire$/) do |some_text|
|
|
11
12
|
@output.puts some_text
|
12
13
|
end
|
13
14
|
|
15
|
+
Alors(/^je m'attends à voir:$/) do |result|
|
16
|
+
@output.string.should == result
|
17
|
+
end
|
18
|
+
|
14
19
|
# End of file
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
#
|
2
|
+
# "Traduction" en Français des macro-pas de Macros4Cuke
|
3
|
+
# Ce sont des définitions de pas faisant directement appel à l'API de Macros4Cuke
|
3
4
|
|
4
5
|
|
5
6
|
Etantdonné(/^que je crée le pas "(?:Soit|Quand|Alors) j(?:e |')\[((?:[^\\\]]|\\.)+)\](:?)" qui équivaut à:$/) do |macro_phrase, colon_capture, template|
|
@@ -17,7 +18,7 @@ end
|
|
17
18
|
Quand(/^j(?:e |')\[([^\]]+)\]:$/) do |macro_phrase, table_argument|
|
18
19
|
# Ensure that the second argument is of the correct type
|
19
20
|
unless table_argument.kind_of?(Cucumber::Ast::Table)
|
20
|
-
error_message = '
|
21
|
+
error_message = 'Ce pas doit avoir un tableau comme paramètre.'
|
21
22
|
fail(Macros4Cuke::DataTableNotFound, error_message)
|
22
23
|
end
|
23
24
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8 You should see a paragraph character: §
|
2
|
+
# File: use_macros4cuke.rb
|
3
|
+
# Purpose: Add the support for macros in Cucumber.
|
4
|
+
# This file is meant to be put next to the 'env.rb' file
|
5
|
+
# of your Cucumber project.
|
6
|
+
|
7
|
+
|
8
|
+
# Load modules, classes and step definitions from the macros4cuke gem
|
9
|
+
require 'macros4cuke/cucumber'
|
10
|
+
|
11
|
+
|
12
|
+
# End of file
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# language: nl
|
2
|
+
Functionaliteit: Macro-stappen
|
3
|
+
Om gemakkelijker scenarios te kunnen schrijven
|
4
|
+
Als Cucumber-gebruiker
|
5
|
+
Wil ik macro-stappen kunnen definieëren en toepassen
|
6
|
+
|
7
|
+
Scenario: Definitie van een macro-stap (van een scenario)
|
8
|
+
Gegeven dat ik de stap "Als ik [de tekst <een_tekst> print]" definieër als:
|
9
|
+
"""
|
10
|
+
Als ik "<een_tekst>" op het scherm afdruk
|
11
|
+
En ik bewaar "<een_tekst>" in geheugen
|
12
|
+
"""
|
13
|
+
|
14
|
+
Scenario: Gebruik van de macro-stap
|
15
|
+
Als ik [de tekst "Hallo" print]
|
16
|
+
Dan verwacht ik te zien:
|
17
|
+
"""
|
18
|
+
Hallo
|
19
|
+
|
20
|
+
"""
|
21
|
+
|
22
|
+
|
23
|
+
Scenario: Definitie van een macro-stap dat macro-stap(pen) gebruikt
|
24
|
+
Gegeven dat ik de stap "Als ik [de tekst <een_tekst> drie keer print]" definieër als:
|
25
|
+
"""
|
26
|
+
Als ik [de tekst "<een_tekst>" print]
|
27
|
+
Als ik [de tekst "<een_tekst>" print]
|
28
|
+
Als ik [de tekst "<een_tekst>" print]
|
29
|
+
"""
|
30
|
+
|
31
|
+
Scenario: Gebruik van laatste macro-step
|
32
|
+
Als ik [de tekst "Drie maal!" drie keer print]
|
33
|
+
Dan verwacht ik te zien:
|
34
|
+
"""
|
35
|
+
Drie maal!
|
36
|
+
Drie maal!
|
37
|
+
Drie maal!
|
38
|
+
|
39
|
+
"""
|
40
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Een paar stappen definities.
|
3
|
+
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
|
7
|
+
Als(/^ik "(.*?)" op het scherm afdruk$/) do |some_text|
|
8
|
+
$stderr.puts some_text
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
Als(/^ik bewaar "(.*?)" in geheugen$/) do |some_text|
|
13
|
+
@output ||= StringIO.new('')
|
14
|
+
@output.puts some_text
|
15
|
+
end
|
16
|
+
|
17
|
+
Dan(/^verwacht ik te zien:$/) do |result|
|
18
|
+
@output.string.should == result
|
19
|
+
end
|
20
|
+
|
21
|
+
# End of file
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# "Vertaling" in het Nederlands van macrostappen van Macros4Cuke
|
3
|
+
# Dit zijn stappen definities dat rechstreeks het API van Macros4Cuke gebruiken
|
4
|
+
|
5
|
+
|
6
|
+
Gegeven(/^dat ik de stap "(?:Gegeven dat|Als|Dan) ik \[((?:[^\\\]]|\\.)+)\](:?)" definieër als:$/) do |macro_phrase, colon_capture, template|
|
7
|
+
use_table = (colon_capture == ':')
|
8
|
+
add_macro(macro_phrase, template, use_table)
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
Als(/^ik \[((?:[^\\\]]|\\.)+)\]$/) do |macro_phrase|
|
13
|
+
# This will call the macro with the given phrase
|
14
|
+
invoke_macro(macro_phrase)
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
Als(/^ik \[([^\]]+)\]:$/) do |macro_phrase, table_argument|
|
19
|
+
# Ensure that the second argument is of the correct type
|
20
|
+
unless table_argument.kind_of?(Cucumber::Ast::Table)
|
21
|
+
error_message = 'Deze stap vereist een tabel als parameter.'
|
22
|
+
fail(Macros4Cuke::DataTableNotFound, error_message)
|
23
|
+
end
|
24
|
+
|
25
|
+
# This will call the macro with the given phrase.
|
26
|
+
# The second argument consists of an array with couples
|
27
|
+
# of the kind: [argument name, actual value]
|
28
|
+
invoke_macro(macro_phrase, table_argument.raw)
|
29
|
+
end
|
30
|
+
|
31
|
+
# End of file
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8 You should see a paragraph character: §
|
2
|
+
# File: use_macros4cuke.rb
|
3
|
+
# Purpose: Add the support for macros in Cucumber.
|
4
|
+
# This file is meant to be put next to the 'env.rb' file
|
5
|
+
# of your Cucumber project.
|
6
|
+
|
7
|
+
|
8
|
+
# Load modules, classes and step definitions from the macros4cuke gem
|
9
|
+
require 'macros4cuke/cucumber'
|
10
|
+
|
11
|
+
|
12
|
+
# End of file
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# File: use_macros4cuke.rb
|
2
|
+
# Purpose: Add the support for macros in a Cucumber project.
|
3
|
+
# This file is meant to be put next to the 'env.rb' file
|
4
|
+
# of your Cucumber project.
|
5
|
+
|
6
|
+
|
7
|
+
# Load modules, classes and step definitions from the macros4cuke gem
|
8
|
+
require 'macros4cuke/cucumber'
|
9
|
+
|
10
|
+
|
11
|
+
# End of file
|
data/lib/macros4cuke.rb
CHANGED
@@ -0,0 +1,75 @@
|
|
1
|
+
# File: application.rb
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
require_relative 'cli/cmd-line'
|
6
|
+
|
7
|
+
module Macros4Cuke # Module used as a namespace
|
8
|
+
|
9
|
+
# Runner for the Macros4Cuke application.
|
10
|
+
class Application
|
11
|
+
attr_reader(:options)
|
12
|
+
|
13
|
+
public
|
14
|
+
|
15
|
+
def initialize()
|
16
|
+
@options = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
# Entry point for the application object.
|
20
|
+
def run!(theCmdLineArgs)
|
21
|
+
@options = options_from(theCmdLineArgs)
|
22
|
+
if options[:setup]
|
23
|
+
options[:setup].each do |a_path|
|
24
|
+
setup_project(a_path)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
# Retrieve the user-entered command-line options
|
32
|
+
def options_from(theCmdLineArgs)
|
33
|
+
cli = CLI::CmdLine.new
|
34
|
+
cli.parse!(theCmdLineArgs.dup)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Make the Cucumber project at the designated path
|
38
|
+
# ready for macros.
|
39
|
+
# In practice, this is obtained by adding a file
|
40
|
+
# in the /features/support dir.
|
41
|
+
def setup_project(aPath)
|
42
|
+
file_name = 'use_macros4cuke'
|
43
|
+
prefix = aPath.relative? ? './' : ''
|
44
|
+
destination = prefix + aPath.to_s + '/' + file_name + '.rb'
|
45
|
+
|
46
|
+
begin
|
47
|
+
fail SupportFileExists.new(destination) if File.exist?(destination)
|
48
|
+
|
49
|
+
template_pathname = Macros4Cuke::RootDir + 'templates/use_macros4cuke.erb'
|
50
|
+
template = File.read(template_pathname)
|
51
|
+
|
52
|
+
|
53
|
+
# Create a context for variables used in our templates
|
54
|
+
prog_version = Macros4Cuke::Version
|
55
|
+
|
56
|
+
# Create one template engine instance
|
57
|
+
engine = ERB.new(template)
|
58
|
+
|
59
|
+
# Generate the text representation with given context
|
60
|
+
file_text = engine.result(binding)
|
61
|
+
|
62
|
+
# Write file contents to file in binary mode in order to avoid eol
|
63
|
+
# consisting of CRLF
|
64
|
+
File.open(destination, 'wb') { |theFile| theFile.write(file_text) }
|
65
|
+
rescue Macros4Cuke::CmdLineError => exc
|
66
|
+
$stderr.puts exc.message
|
67
|
+
exit
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end # class
|
72
|
+
|
73
|
+
end # module
|
74
|
+
|
75
|
+
# End of file
|