active_cucumber 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd6e427a1ea5dd697035f91e1344e7dbfe0f8717
4
- data.tar.gz: 0998293ca8816de728f5f1b5419e350ac42f712c
3
+ metadata.gz: 96a25a05107846a537f60fc80260a9ee6b97f3c8
4
+ data.tar.gz: a7fb3796f5d4ebaa91548f42fdaef7b254a9024e
5
5
  SHA512:
6
- metadata.gz: 0c2ce7cc37de5e7bd600080238d73f8c10f7db99b623db4a51208d7cef6ea66697de28b814830d732df24ea1608f3cb7b15b06e313edf7a158b6c031a4bd5c78
7
- data.tar.gz: 12bad9a4a815ba38efefed654a9175cf276317d6aea7c9f658a9e7c45db9fe4c9cfea613a6145338ac164f28c4f78b8bd9b44e879ae5a2022bde47e3018f36bc
6
+ metadata.gz: 32929e7bd142fe4b48f84ffa3b9d6e565ea3ed710ad0d3b72ceb0032159a66b84dd1288dfad9a6dd39f9238ddbb72f8f196133d6a55d2b113cf263609b1bb58b
7
+ data.tar.gz: 66855ff32104d2d3b7ffb69a7807a792e12a5b5251d95035940674cb36458e8a2b57d68a717fd5a5cd5434fdd3906868b38998c71c6493f8b912e55e65788c3f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_cucumber (0.0.4)
4
+ active_cucumber (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,25 +1,29 @@
1
1
  # ActiveCucumber [![Circle CI](https://circleci.com/gh/Originate/active_cucumber.svg?style=shield)](https://circleci.com/gh/Originate/active_cucumber)
2
2
 
3
- High-level Cucumber helpers for [creating](#creating-database-records)
4
- and [verifying](#verifying-database-records)
3
+ High-level Cucumber helpers for performing
5
4
  [ActiveRecord](http://guides.rubyonrails.org/active_record_basics.html)-based
6
- database entries using Cucumber tables.
5
+ database operations using Cucumber tables in tests.
7
6
 
8
7
 
9
8
  ## Creating database records
10
9
 
11
- Creating simple fields works out of the box.
12
- Let's assume we have an application that stores TV shows and their episodes,
13
- and our tests contain this Cucumber table:
10
+ ActiveCucumber allows to create ActiveRecord objects from data in Cucumber tables.
11
+
12
+ Let's assume we have an application that stores TV shows and their episodes.
13
+
14
+
15
+ ### Creating simple fields
16
+
17
+ Simple fields works out of the box. Let's say our tests contain this Cucumber table:
14
18
 
15
19
  ```cucumber
16
20
  Given the episodes:
17
- | NAME | YEAR |
18
- | Encounter at Farpoint | 1987 |
19
- | All Good Things | 1994 |
21
+ | NAME |
22
+ | Encounter at Farpoint |
23
+ | All Good Things |
20
24
  ```
21
25
 
22
- Implementing this step looks like:
26
+ ActiveCucumber makes it trivially easy to implement this step:
23
27
 
24
28
  ```ruby
25
29
  Given(/^the episodes:$/) do |table|
@@ -54,9 +58,11 @@ class EpisodeCreator < ActiveCucumber::Creator
54
58
  end
55
59
  ```
56
60
 
57
- ActiveCucumber automatically uses creator classes that follow the given naming schema:
58
- * name is `<class name>Creator`
59
- * method names are `value_for_<attribute name>`
61
+ ActiveCucumber automatically uses classes named `<class name>Creator`
62
+ as creator classes for the respective class.
63
+ This class must have methods named `value_for_<attribute name>`.
64
+ They receive the value of the respective attribute in the Cucumber table (a string),
65
+ and return whatever value should be assigned to that attribute on the ActiveRecord instance.
60
66
 
61
67
 
62
68
  ### Other columns
@@ -64,6 +70,9 @@ ActiveCucumber automatically uses creator classes that follow the given naming s
64
70
  Cucumber tables can contain columns that provide other test data,
65
71
  and don't correspond to attributes on the created object.
66
72
 
73
+ For example, let's say series belong to a `Genre` class that specifies
74
+ the genre that the series is in.
75
+
67
76
  ```cucumber
68
77
  Given the episodes:
69
78
  | GENRE | SERIES | NAME |
@@ -71,8 +80,15 @@ Given the episodes:
71
80
  | Comedy | The Big Bang Theory | The Big Bran Hypothesis |
72
81
  ```
73
82
 
74
- A `Genre` has many series, and a series belongs to a genre.
75
- Episodes are not directly associated with genres.
83
+ Implementing this with Creators is simple:
84
+
85
+ Creators decorate the data structure that
86
+ is sent to FactoryGirl to create the record.
87
+ This means `self` inside creator methods behaves like a Hash
88
+ that is pre-populated with the Cucumber table data.
89
+ You can modify this hash, use other field values,
90
+ add or remove fields,
91
+ or store instance variables to be used later.
76
92
 
77
93
  ```ruby
78
94
  class EpisodeCreator < ActiveCucumber::Creator
@@ -82,21 +98,13 @@ class EpisodeCreator < ActiveCucumber::Creator
82
98
  delete :genre
83
99
  end
84
100
 
85
- def value_for_show show_name
86
- Show.find_by(name: show_name) || FactoryGirl.create(:show, name: show_name, genre: @genre)
101
+ def value_for_series series_name
102
+ Series.find_by(name: series_name) || FactoryGirl.create(:series, name: series_name, genre: @genre)
87
103
  end
88
104
 
89
105
  end
90
106
  ```
91
107
 
92
- Creators decorate the data structure that
93
- is sent to FactoryGirl to create the record.
94
- This means `self` inside creator methods behaves like a Hash
95
- that is pre-populated with the Cucumber table data.
96
- You can modify this hash, use other field values,
97
- add or remove fields,
98
- or store instance variables to be used later.
99
-
100
108
 
101
109
  ## Verifying database records
102
110
 
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'active_cucumber'
6
- s.version = '0.0.4'
6
+ s.version = '0.0.5'
7
7
  s.authors = ['Kevin Goslar']
8
8
  s.email = ['kevin.goslar@gmail.com']
9
9
  s.summary = %s(ActiveRecord tools for Cucumber)
@@ -13,6 +13,7 @@ module ActiveCucumber
13
13
  builder.create_many ActiveCucumber.horizontal_table(cucumber_table)
14
14
  end
15
15
 
16
+
16
17
  # Creates an entry of the given ActiveRecord class
17
18
  # specified by the given vertical Cucumber table
18
19
  def self.create_one activerecord_class, cucumber_table
@@ -49,5 +50,4 @@ module ActiveCucumber
49
50
  table.rows_hash
50
51
  end
51
52
 
52
-
53
53
  end
@@ -1,11 +1,10 @@
1
1
  module ActiveCucumber
2
2
 
3
- # Converts an attributes hash in Cucumber format
4
- # into a hash consumable by FactoryGirl
5
- #
6
- # Subclasses define methods to convert particular fields.
3
+ # Creates ActiveRecord entries with data from given Cucumber tables.
7
4
  class Creator
8
5
 
6
+ include FactoryGirl::Syntax::Methods
7
+
9
8
  def initialize attributes
10
9
  @attributes = attributes
11
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_cucumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Goslar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-23 00:00:00.000000000 Z
11
+ date: 2015-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -218,8 +218,8 @@ files:
218
218
  - features/step_definitions/steps.rb
219
219
  - features/support/env.rb
220
220
  - features/support/episode.rb
221
+ - features/support/episode_creator.rb
221
222
  - features/support/episode_cucumberator.rb
222
- - features/support/episode_cureator.rb
223
223
  - features/support/genre.rb
224
224
  - features/support/show.rb
225
225
  - features/support/show_cucumberator.rb