active_cucumber 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +35 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +89 -0
- data/LICENSE.txt +22 -0
- data/README.md +92 -0
- data/Rakefile +12 -0
- data/active_cucumber.gemspec +26 -0
- data/circle.yml +16 -0
- data/features/cucumparer/diff_all.feature +71 -0
- data/features/cucumparer/diff_one.feature +55 -0
- data/features/step_definitions/steps.rb +44 -0
- data/features/support/env.rb +29 -0
- data/features/support/episode.rb +3 -0
- data/features/support/episode_cucumberator.rb +7 -0
- data/features/support/show.rb +3 -0
- data/lib/active_cucumber/cucumberator.rb +54 -0
- data/lib/active_cucumber/cucumparer.rb +53 -0
- data/lib/active_cucumber.rb +22 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 31fc83494b273be00aaa3b52b7d3376a31b86e55
|
4
|
+
data.tar.gz: d1ca0c141ab1195f7e2cd8637dc993e2b57cb08b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3d951e2e1ae6b2f2a401589d9c601bb0de1e470c0ddbbe3f4c516f1caa1d9a398500eac0e29b0dee8c4e0fe17db4b1c1df6c9887cbc5f017a11c6bef48a8d79
|
7
|
+
data.tar.gz: 59146c0d3fc96562c18e45a16efbf7bfec5a4e4eb07cbf6fbf9e15bbc0b540f8ec8afd1f8504001cceea96f7e613ed8b633a8c1a53a9e3d7e6476c22483a5d41
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/.bundle/
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
AllCops:
|
2
|
+
|
3
|
+
DisplayCopNames: true
|
4
|
+
|
5
|
+
DisplayStyleGuide: true
|
6
|
+
|
7
|
+
Include:
|
8
|
+
- '**/Rakefile'
|
9
|
+
|
10
|
+
|
11
|
+
Lint/Eval:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
|
15
|
+
Metrics/LineLength:
|
16
|
+
Max: 100
|
17
|
+
|
18
|
+
|
19
|
+
Style/AccessModifierIndentation:
|
20
|
+
EnforcedStyle: outdent
|
21
|
+
|
22
|
+
Style/Documentation:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/EmptyLines:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Style/EmptyLinesAroundClassBody:
|
29
|
+
Enabled: false
|
30
|
+
|
31
|
+
Style/EmptyLinesAroundModuleBody:
|
32
|
+
EnforcedStyle: empty_lines
|
33
|
+
|
34
|
+
Style/MethodDefParentheses:
|
35
|
+
EnforcedStyle: require_no_parentheses
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
active_cucumber (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (4.2.4)
|
10
|
+
activesupport (= 4.2.4)
|
11
|
+
builder (~> 3.1)
|
12
|
+
activerecord (4.2.4)
|
13
|
+
activemodel (= 4.2.4)
|
14
|
+
activesupport (= 4.2.4)
|
15
|
+
arel (~> 6.0)
|
16
|
+
activesupport (4.2.4)
|
17
|
+
i18n (~> 0.7)
|
18
|
+
json (~> 1.7, >= 1.7.7)
|
19
|
+
minitest (~> 5.1)
|
20
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
21
|
+
tzinfo (~> 1.1)
|
22
|
+
arel (6.0.3)
|
23
|
+
ast (2.1.0)
|
24
|
+
astrolabe (1.3.1)
|
25
|
+
parser (~> 2.2)
|
26
|
+
builder (3.2.2)
|
27
|
+
cucumber (2.1.0)
|
28
|
+
builder (>= 2.1.2)
|
29
|
+
cucumber-core (~> 1.3.0)
|
30
|
+
diff-lcs (>= 1.1.3)
|
31
|
+
gherkin3 (~> 3.1.0)
|
32
|
+
multi_json (>= 1.7.5, < 2.0)
|
33
|
+
multi_test (>= 0.1.2)
|
34
|
+
cucumber-core (1.3.0)
|
35
|
+
gherkin3 (~> 3.1.0)
|
36
|
+
diff-lcs (1.2.5)
|
37
|
+
gherkin3 (3.1.2)
|
38
|
+
i18n (0.7.0)
|
39
|
+
json (1.8.3)
|
40
|
+
minitest (5.8.1)
|
41
|
+
mortadella (0.2.1)
|
42
|
+
multi_json (1.11.2)
|
43
|
+
multi_test (0.1.2)
|
44
|
+
parser (2.2.3.0)
|
45
|
+
ast (>= 1.1, < 3.0)
|
46
|
+
powerpack (0.1.1)
|
47
|
+
rainbow (2.0.0)
|
48
|
+
rake (10.4.2)
|
49
|
+
rspec (3.3.0)
|
50
|
+
rspec-core (~> 3.3.0)
|
51
|
+
rspec-expectations (~> 3.3.0)
|
52
|
+
rspec-mocks (~> 3.3.0)
|
53
|
+
rspec-core (3.3.2)
|
54
|
+
rspec-support (~> 3.3.0)
|
55
|
+
rspec-expectations (3.3.1)
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
+
rspec-support (~> 3.3.0)
|
58
|
+
rspec-mocks (3.3.2)
|
59
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
60
|
+
rspec-support (~> 3.3.0)
|
61
|
+
rspec-support (3.3.0)
|
62
|
+
rubocop (0.34.2)
|
63
|
+
astrolabe (~> 1.3)
|
64
|
+
parser (>= 2.2.2.5, < 3.0)
|
65
|
+
powerpack (~> 0.1)
|
66
|
+
rainbow (>= 1.99.1, < 3.0)
|
67
|
+
ruby-progressbar (~> 1.4)
|
68
|
+
ruby-progressbar (1.7.5)
|
69
|
+
sqlite3 (1.3.11)
|
70
|
+
thread_safe (0.3.5)
|
71
|
+
tzinfo (1.2.2)
|
72
|
+
thread_safe (~> 0.1)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
ruby
|
76
|
+
|
77
|
+
DEPENDENCIES
|
78
|
+
active_cucumber!
|
79
|
+
activerecord
|
80
|
+
bundler
|
81
|
+
cucumber
|
82
|
+
mortadella
|
83
|
+
rake
|
84
|
+
rspec
|
85
|
+
rubocop
|
86
|
+
sqlite3
|
87
|
+
|
88
|
+
BUNDLED WITH
|
89
|
+
1.10.6
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Originate
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# ActiveCucumber [](https://circleci.com/gh/Originate/active_cucumber)
|
2
|
+
|
3
|
+
High-level Cucumber helpers for testing
|
4
|
+
[ActiveRecord](http://guides.rubyonrails.org/active_record_basics.html)-based
|
5
|
+
database applications using Cucumber tables.
|
6
|
+
|
7
|
+
|
8
|
+
## Verifying database records
|
9
|
+
|
10
|
+
ActiveCucumber allows to compare ActiveRecord objects
|
11
|
+
against Cucumber tables,
|
12
|
+
with the differences visualized intuitively as a Cucumber table diff.
|
13
|
+
Only the attributes provided in the table are compared,
|
14
|
+
the ones not listed are ignored.
|
15
|
+
|
16
|
+
|
17
|
+
### diff_one!
|
18
|
+
|
19
|
+
`ActiveCucumber.diff_one!` compares the given ActiveRecord entry with the given
|
20
|
+
_vertical_ Cucumber table.
|
21
|
+
These tables have their headers on the left side, and are used to describe
|
22
|
+
a single record in greater detail.
|
23
|
+
|
24
|
+
```cucumber
|
25
|
+
When loading the last Star Trek TNG episode
|
26
|
+
Then it returns this episode:
|
27
|
+
| SHOW | Star Trek TNG |
|
28
|
+
| NAME | All Good Things |
|
29
|
+
| YEAR | 1994 |
|
30
|
+
```
|
31
|
+
|
32
|
+
The `Then` step is easy to implement with ActiveCucumber:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
Then /^it returns this episode:$/ do |table|
|
36
|
+
# @episode contains one loaded entry
|
37
|
+
ActiveCucumber.diff_one! @episode, table
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
|
42
|
+
### diff_all!
|
43
|
+
|
44
|
+
`ActiveCucumber.diff_all!` verifies that the given _horizontal_ Cucumber table
|
45
|
+
describes all existing database entries of the given class.
|
46
|
+
Horizontal Cucumber tables have their headers on top, and define several
|
47
|
+
records at once:
|
48
|
+
|
49
|
+
```cucumber
|
50
|
+
When I run the importer script with parameter "count=3"
|
51
|
+
Then the database contains these episodes:
|
52
|
+
| SHOW | NAME | YEAR |
|
53
|
+
| Star Trek TNG | Encounter at Farpoint | 1987 |
|
54
|
+
| Star Trek TNG | The Nth Degree | 1991 |
|
55
|
+
| Star Trek TNG | All Good Things | 1994 |
|
56
|
+
```
|
57
|
+
|
58
|
+
The last step would be implemented as:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
Then /^Then the database contains these episodes:$/ do |table|
|
62
|
+
ActiveCucumber.diff_all! Episode, table
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
The Cucumber table should list the entries sorted by `created_at` timestamp.
|
67
|
+
|
68
|
+
|
69
|
+
### Cucumberators
|
70
|
+
|
71
|
+
ActiveCucumber converts the database records into a data table
|
72
|
+
and matches it against the given Cucumber table.
|
73
|
+
|
74
|
+
By default, all attributes are converted into a String.
|
75
|
+
It is possible to customize this conversion step by creating a
|
76
|
+
_Cucumberator_ (short for Cucumber Decorator).
|
77
|
+
This class decorates an ActiveRecord instance, and defines converters
|
78
|
+
for attribute values into the format used in the Cucumber table.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
class EpisodeCucumberator < Cucumberator
|
82
|
+
|
83
|
+
# In the SHOW column, print the name of the show of the episode truncated
|
84
|
+
def value_of_show
|
85
|
+
show.name.truncate 10
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
ActiveCucumber automatically finds and uses these Cucumberators if this
|
92
|
+
naming convention is followed.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'active_cucumber'
|
6
|
+
s.version = '0.0.1'
|
7
|
+
s.authors = ['Kevin Goslar']
|
8
|
+
s.email = ['kevin.goslar@gmail.com']
|
9
|
+
s.summary = %s(ActiveRecord tools for Cucumber)
|
10
|
+
s.description = %s(Tools to compare ActiveRecord entries with Cucumber tables)
|
11
|
+
s.homepage = 'https://github.com/Originate/active_cucumber'
|
12
|
+
s.license = 'MIT'
|
13
|
+
|
14
|
+
s.files = `git ls-files -z`.split("\x0")
|
15
|
+
s.test_files = Dir['features/*']
|
16
|
+
s.require_paths = ['lib']
|
17
|
+
|
18
|
+
s.add_development_dependency 'activerecord'
|
19
|
+
s.add_development_dependency 'bundler'
|
20
|
+
s.add_development_dependency 'cucumber'
|
21
|
+
s.add_development_dependency 'mortadella'
|
22
|
+
s.add_development_dependency 'rake'
|
23
|
+
s.add_development_dependency 'rubocop'
|
24
|
+
s.add_development_dependency 'rspec'
|
25
|
+
s.add_development_dependency 'sqlite3'
|
26
|
+
end
|
data/circle.yml
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
Feature: Cucumparer.diff_all!
|
2
|
+
|
3
|
+
As a Cucumber user
|
4
|
+
I want to verify all existing records using a Cucumber table
|
5
|
+
So that I can easily and intuitively check the result of my database-facing operations.
|
6
|
+
|
7
|
+
|
8
|
+
Background:
|
9
|
+
Given the TV episodes:
|
10
|
+
| SHOW | NAME | YEAR |
|
11
|
+
| Star Trek TNG | Encounter at Farpoint | 1987 |
|
12
|
+
| Star Trek TNG | All Good Things | 1994 |
|
13
|
+
|
14
|
+
|
15
|
+
Scenario: verifying string fields
|
16
|
+
When running "ActiveCucumber.diff_all! Episode, table" with this table:
|
17
|
+
| NAME |
|
18
|
+
| Encounter at Farpoint |
|
19
|
+
| All Good Things |
|
20
|
+
Then the test passes
|
21
|
+
|
22
|
+
|
23
|
+
Scenario: verifying non-string fields
|
24
|
+
When running "ActiveCucumber.diff_all! Episode, table" with this table:
|
25
|
+
| YEAR |
|
26
|
+
| 1987 |
|
27
|
+
| 1994 |
|
28
|
+
Then the test passes
|
29
|
+
|
30
|
+
|
31
|
+
Scenario: verifying associated fields through a Cucumberator
|
32
|
+
When running "ActiveCucumber.diff_all! Episode, table" with this table:
|
33
|
+
| SHOW | NAME |
|
34
|
+
| Star Trek TNG | Encounter at Farpoint |
|
35
|
+
| Star Trek TNG | All Good Things |
|
36
|
+
Then the test passes
|
37
|
+
|
38
|
+
|
39
|
+
Scenario: complete table match
|
40
|
+
When running "ActiveCucumber.diff_all! Episode, table" with this table:
|
41
|
+
| SHOW | NAME | YEAR |
|
42
|
+
| Star Trek TNG | Encounter at Farpoint | 1987 |
|
43
|
+
| Star Trek TNG | All Good Things | 1994 |
|
44
|
+
Then the test passes
|
45
|
+
|
46
|
+
|
47
|
+
Scenario: missing a record
|
48
|
+
When running "ActiveCucumber.diff_all! Episode, table" with this table:
|
49
|
+
| SHOW | NAME |
|
50
|
+
| Star Trek TNG | Encounter at Farpoint |
|
51
|
+
Then the test fails
|
52
|
+
And Cucumparer prints the error message "Tables were not identical"
|
53
|
+
|
54
|
+
|
55
|
+
Scenario: an extra record
|
56
|
+
When running "ActiveCucumber.diff_all! Episode, table" with this table:
|
57
|
+
| SHOW | NAME |
|
58
|
+
| Star Trek TNG | Encounter at Farpoint |
|
59
|
+
| Star Trek TNG | All Good Things |
|
60
|
+
| Star Trek TNG | The Nth Degree |
|
61
|
+
Then the test fails
|
62
|
+
And Cucumparer prints the error message "Tables were not identical"
|
63
|
+
|
64
|
+
|
65
|
+
Scenario: mismatching data in a table cell
|
66
|
+
When running "ActiveCucumber.diff_all! Episode, table" with this table:
|
67
|
+
| SHOW | NAME |
|
68
|
+
| Star Trek TOS | Encounter at Farpoint |
|
69
|
+
| Star Trek TNG | All Good Things |
|
70
|
+
Then the test fails
|
71
|
+
And Cucumparer prints the error message "Tables were not identical"
|
@@ -0,0 +1,55 @@
|
|
1
|
+
Feature: Cucumparer.diff_one!
|
2
|
+
|
3
|
+
As a Cucumber user
|
4
|
+
I want to verify a single record using a detailed Cucumber table
|
5
|
+
So that I can easily and intuitively check individual database entries.
|
6
|
+
|
7
|
+
|
8
|
+
Background:
|
9
|
+
Given the TV episode:
|
10
|
+
| SHOW | Star Trek TNG |
|
11
|
+
| NAME | All Good Things |
|
12
|
+
| YEAR | 1994 |
|
13
|
+
|
14
|
+
|
15
|
+
Scenario: verifying string fields
|
16
|
+
When running "ActiveCucumber.diff_one! @episode, table" with this table:
|
17
|
+
| NAME | All Good Things |
|
18
|
+
Then the test passes
|
19
|
+
|
20
|
+
|
21
|
+
Scenario: verifying non-string fields
|
22
|
+
When running "ActiveCucumber.diff_one! @episode, table" with this table:
|
23
|
+
| YEAR | 1994 |
|
24
|
+
Then the test passes
|
25
|
+
|
26
|
+
|
27
|
+
Scenario: verifying associated fields
|
28
|
+
When running "ActiveCucumber.diff_one! @episode, table" with this table:
|
29
|
+
| SHOW | Star Trek TNG |
|
30
|
+
| NAME | All Good Things |
|
31
|
+
Then the test passes
|
32
|
+
|
33
|
+
|
34
|
+
Scenario: complete table match
|
35
|
+
When running "ActiveCucumber.diff_one! @episode, table" with this table:
|
36
|
+
| SHOW | Star Trek TNG |
|
37
|
+
| NAME | All Good Things |
|
38
|
+
| YEAR | 1994 |
|
39
|
+
Then the test passes
|
40
|
+
|
41
|
+
|
42
|
+
Scenario: providing a non-existing field
|
43
|
+
When running "ActiveCucumber.diff_one! @episode, table" with this table:
|
44
|
+
| NAME | All Good Things |
|
45
|
+
| FOOBAR | 1994 |
|
46
|
+
Then the test fails
|
47
|
+
And Cucumparer prints the error message "undefined method.*foobar"
|
48
|
+
|
49
|
+
|
50
|
+
Scenario: mismatching data in a table cell
|
51
|
+
When running "ActiveCucumber.diff_one! @episode, table" with this table:
|
52
|
+
| SHOW | Star Trek TOS |
|
53
|
+
| NAME | All Good Things |
|
54
|
+
Then the test fails
|
55
|
+
And Cucumparer prints the error message "Tables were not identical"
|
@@ -0,0 +1,44 @@
|
|
1
|
+
Given(/^the TV episode:$/) do |table|
|
2
|
+
data = table.rows_hash
|
3
|
+
show = Show.find_or_create_by name: data['SHOW']
|
4
|
+
@episode = show.episodes.create name: data['NAME'], year: data['YEAR']
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
Given(/^the TV episodes:$/) do |table|
|
9
|
+
table.map_headers! { |header| header.downcase.to_sym }
|
10
|
+
table.hashes.each do |row|
|
11
|
+
show = Show.find_or_create_by name: row[:show]
|
12
|
+
show.episodes.create name: row[:name], year: row[:year]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
# rubocop:disable Lint/UnusedBlockArgument
|
19
|
+
Then(/^running "([^"]+)" with this table:$/) do |code, table|
|
20
|
+
begin
|
21
|
+
@exception = false
|
22
|
+
@result = eval code
|
23
|
+
rescue StandardError => e
|
24
|
+
@exception = true
|
25
|
+
@error_message = e.message
|
26
|
+
end
|
27
|
+
end
|
28
|
+
# rubocop:enable Lint/UnusedBlockArgument
|
29
|
+
|
30
|
+
|
31
|
+
Then(/^the test passes$/) do
|
32
|
+
p @error_message if @expectation == true
|
33
|
+
expect(@exception).to be false
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
Then(/^the test fails$/) do
|
38
|
+
expect(@exception).to be true
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
Then(/^Cucumparer prints the error message "([^"]*)"$/) do |expected_error|
|
43
|
+
expect(@error_message).to match expected_error
|
44
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
require 'sqlite3'
|
3
|
+
require 'mortadella'
|
4
|
+
require 'active_cucumber'
|
5
|
+
|
6
|
+
|
7
|
+
ActiveRecord::Base.establish_connection(
|
8
|
+
adapter: 'sqlite3',
|
9
|
+
database: ':memory:'
|
10
|
+
)
|
11
|
+
|
12
|
+
ActiveRecord::Schema.define do
|
13
|
+
create_table :shows, force: true do |t|
|
14
|
+
t.string :name
|
15
|
+
t.datetime 'created_at'
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table :episodes, force: true do |t|
|
19
|
+
t.belongs_to :show, index: true
|
20
|
+
t.string :name
|
21
|
+
t.integer :year
|
22
|
+
t.datetime 'created_at'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Before do
|
27
|
+
Show.delete_all
|
28
|
+
Episode.delete_all
|
29
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module ActiveCucumber
|
2
|
+
|
3
|
+
# A decorator for ActiveRecord objects that adds methods to
|
4
|
+
# format record attributes as they are displayed in Cucumber tables.
|
5
|
+
#
|
6
|
+
# This class is used by default. You can subclass it to create
|
7
|
+
# custom Cucumberators for your ActiveRecord classes.
|
8
|
+
class Cucumberator
|
9
|
+
|
10
|
+
# object - the instance to decorate
|
11
|
+
def initialize object
|
12
|
+
@object = object
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
# Returns the Cucumber value for the given attribute key.
|
17
|
+
#
|
18
|
+
# If a value_for_* method is not defined for the given key,
|
19
|
+
# returns the attribute value of the decorated object,
|
20
|
+
# converted to a String.
|
21
|
+
def value_for key
|
22
|
+
method_name = value_method_name key
|
23
|
+
if respond_to? method_name
|
24
|
+
send(method_name).to_s
|
25
|
+
else
|
26
|
+
@object.send(normalized_key key).to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def method_missing method_name
|
34
|
+
# This is necessary so that a Cucumberator subclass can access
|
35
|
+
# attributes of @object as if they were its own.
|
36
|
+
@object.send method_name
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# Converts the key given in Cucumber format into the format used to
|
41
|
+
# access attributes on an ActiveRecord instance.
|
42
|
+
def normalized_key key
|
43
|
+
key.to_s.downcase.parameterize.underscore
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# Returns the name of the value_of_* method for the given key
|
48
|
+
def value_method_name key
|
49
|
+
"value_for_#{normalized_key key}"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module ActiveCucumber
|
2
|
+
|
3
|
+
class Cucumparer
|
4
|
+
|
5
|
+
def initialize clazz, cucumber_table
|
6
|
+
@clazz = clazz
|
7
|
+
@cucumber_table = cucumber_table
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns all entries in the database as a horizontal Mortadella table
|
11
|
+
def to_horizontal_table
|
12
|
+
mortadella = Mortadella::Horizontal.new headers: @cucumber_table.headers
|
13
|
+
@clazz.order('created_at ASC').each do |record|
|
14
|
+
cucumberator = cucumberator_for record
|
15
|
+
mortadella << @cucumber_table.headers.map do |header|
|
16
|
+
cucumberator.value_for header
|
17
|
+
end
|
18
|
+
end
|
19
|
+
mortadella.table
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns the given object as a vertical Mortadella table
|
23
|
+
def to_vertical_table object
|
24
|
+
mortadella = Mortadella::Vertical.new
|
25
|
+
cucumberator = cucumberator_for object
|
26
|
+
@cucumber_table.rows_hash.each do |key, _|
|
27
|
+
mortadella[key] = cucumberator.value_for key
|
28
|
+
end
|
29
|
+
mortadella.table
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# Returns the Cucumberator subclass to be used by this Cucumparer instance
|
35
|
+
def cucumberator_class
|
36
|
+
cucumberator_class_name.constantize
|
37
|
+
rescue NameError
|
38
|
+
Cucumberator
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the name of the Cucumberator subclass to be used by this Cucumparer instance.
|
42
|
+
def cucumberator_class_name
|
43
|
+
"#{@clazz.name}Cucumberator"
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns the Cucumberator object for the given ActiveRecord instance
|
47
|
+
def cucumberator_for object
|
48
|
+
cucumberator_class.new object
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'active_cucumber/cucumparer'
|
2
|
+
require 'active_cucumber/cucumberator'
|
3
|
+
|
4
|
+
# The main namespace for this gem
|
5
|
+
module ActiveCucumber
|
6
|
+
|
7
|
+
# Verifies that the database table for the given ActiveRecord class
|
8
|
+
# matches the given horizontal Cucumber table.
|
9
|
+
#
|
10
|
+
# Sorts records by creation date.
|
11
|
+
def self.diff_all! clazz, cucumber_table
|
12
|
+
cucumparer = Cucumparer.new clazz, cucumber_table
|
13
|
+
cucumber_table.diff! cucumparer.to_horizontal_table
|
14
|
+
end
|
15
|
+
|
16
|
+
# Verifies that the given object matches the given vertical Cucumber table
|
17
|
+
def self.diff_one! object, cucumber_table
|
18
|
+
cucumparer = Cucumparer.new object.class, cucumber_table
|
19
|
+
cucumber_table.diff! cucumparer.to_vertical_table(object)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_cucumber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kevin Goslar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: cucumber
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mortadella
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sqlite3
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: Tools to compare ActiveRecord entries with Cucumber tables
|
126
|
+
email:
|
127
|
+
- kevin.goslar@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rubocop.yml"
|
134
|
+
- Gemfile
|
135
|
+
- Gemfile.lock
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- active_cucumber.gemspec
|
140
|
+
- circle.yml
|
141
|
+
- features/cucumparer/diff_all.feature
|
142
|
+
- features/cucumparer/diff_one.feature
|
143
|
+
- features/step_definitions/steps.rb
|
144
|
+
- features/support/env.rb
|
145
|
+
- features/support/episode.rb
|
146
|
+
- features/support/episode_cucumberator.rb
|
147
|
+
- features/support/show.rb
|
148
|
+
- lib/active_cucumber.rb
|
149
|
+
- lib/active_cucumber/cucumberator.rb
|
150
|
+
- lib/active_cucumber/cucumparer.rb
|
151
|
+
homepage: https://github.com/Originate/active_cucumber
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.4.5.1
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: ActiveRecord tools for Cucumber
|
175
|
+
test_files: []
|