active_cucumber 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1251d126492dbe37e408de8dba4cfeafd06298c3
4
- data.tar.gz: c5e467f11365e5d087df25c2545a42f4f99151fd
3
+ metadata.gz: 1048545c953152ca466b938200d8ff3394db73e0
4
+ data.tar.gz: 78945b8fe777ae5449fd7c3ce61f6853da5f9cdf
5
5
  SHA512:
6
- metadata.gz: 83fe5661b74b097a5c8e169a203aaea2ef20eef19ad8288af18e0d76a2ba87fe4e330b01e44c5a786acd7463f09f206667a8b09d7f2a0db0ac65fb6b156e092b
7
- data.tar.gz: ec37d1cda1eaf141a961099bd3873c12a7b978f3d8fdddf8ca4aa08eb35f40061867c0ebf7f07dd5349e91a74a6627dd35931c7109f8c5bb396b2c84ce0c175e
6
+ metadata.gz: 5ebaf30097d41bae186253bba0e1dcbdf595e3b593cbad28c466c35a0acc0fbb0aeaeaaf193c4f1f5d20ac0b00195328740697de7e900825651241c539584235
7
+ data.tar.gz: bc8030615a10e8aa15474bafb9e9745645936b151bccb6be1d687970e635b232320d673c2b61938a61054ed58130b1a11920a8b9a6b14fec08ddd939f998c3ad
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_cucumber (0.0.6)
4
+ active_cucumber (0.0.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -105,6 +105,40 @@ class EpisodeCreator < ActiveCucumber::Creator
105
105
  end
106
106
  ```
107
107
 
108
+ ### Context values
109
+
110
+ You can provide extra values to ActiveCucumber that are available as instance
111
+ variables on your creators.
112
+
113
+ Let's say our system has subscriptions for series, and we want to be able to
114
+ use the currently logged in user in them:
115
+
116
+ ```cucumber
117
+ Given the subscriptions:
118
+ | SUBSCRIBER | SHOW |
119
+ | me | Star Trek TNG |
120
+ ```
121
+
122
+ The currently logged in user can be provided to ActiveCucumber using the `context` parameter:
123
+
124
+ ```ruby
125
+ Given(/^the subscriptions:$/) do |table|
126
+ ActiveCucumber.create_many Subscription, table, context: { logged_in_user: @current_user }
127
+ end
128
+ ```
129
+
130
+ In the Creator, the context is available as instance variables:
131
+
132
+ ```ruby
133
+ class SubscriptionCreator < ActiveCucumber::Creator
134
+
135
+ def value_for_subscriber subscriber_name
136
+ subscriber_name == 'me' ? @logged_in_user : subscriber_name
137
+ end
138
+
139
+ end
140
+ ```
141
+
108
142
 
109
143
  ## Verifying database records
110
144
 
@@ -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.6'
6
+ s.version = '0.0.7'
7
7
  s.authors = ['Kevin Goslar']
8
8
  s.email = ['kevin.goslar@gmail.com']
9
9
  s.summary = %s(ActiveRecord tools for Cucumber)
@@ -44,6 +44,15 @@ Feature: ActiveCucumber.create_many
44
44
  | Star Trek TNG | All Good Things |
45
45
 
46
46
 
47
+ Scenario: using context values
48
+ When running "ActiveCucumber.create_many Subscription, table, context: { current_user: 'Q' }" with this table:
49
+ | SUBSCRIBER | SHOW |
50
+ | me | Star Trek TNG |
51
+ Then the database contains the subscriptions:
52
+ | SUBSCRIBER | SHOW |
53
+ | Q | Star Trek TNG |
54
+
55
+
47
56
  Scenario: complex example
48
57
  When running "ActiveCucumber.create_many Episode, table" with this table:
49
58
  | SHOW | NAME | YEAR |
@@ -23,6 +23,15 @@ Feature: ActiveCucumber.create_one
23
23
  And the database contains the show "Star Trek TNG"
24
24
 
25
25
 
26
+ Scenario: using context values
27
+ When running "ActiveCucumber.create_one Subscription, table, context: { current_user: 'Q' }" with this table:
28
+ | SUBSCRIBER | me |
29
+ | SHOW | Star Trek TNG |
30
+ Then the database contains the subscriptions:
31
+ | SUBSCRIBER | SHOW |
32
+ | Q | Star Trek TNG |
33
+
34
+
26
35
  Scenario: complex example
27
36
  When running "ActiveCucumber.create_one Episode, table" with this table:
28
37
  | SHOW | Star Trek TNG |
@@ -32,6 +32,12 @@ ActiveRecord::Schema.define do
32
32
  t.integer :year
33
33
  t.datetime 'created_at'
34
34
  end
35
+
36
+ create_table :subscriptions, force: true do |t|
37
+ t.string :subscriber
38
+ t.belongs_to :show
39
+ t.datetime 'created_at'
40
+ end
35
41
  end
36
42
 
37
43
 
@@ -49,12 +55,18 @@ FactoryGirl.define do
49
55
  year { 1960 + rand(40) }
50
56
  show
51
57
  end
58
+
59
+ factory :subscription do
60
+ subscriber { Faker::Name.name }
61
+ show
62
+ end
52
63
  end
53
64
 
54
65
 
55
66
  Before do
56
67
  Show.delete_all
57
68
  Episode.delete_all
69
+ Subscription.delete_all
58
70
  @error_checked = false
59
71
  end
60
72
 
@@ -1,4 +1,5 @@
1
1
  class Show < ActiveRecord::Base
2
2
  belongs_to :genre
3
3
  has_many :episodes
4
+ has_many :subscriptions
4
5
  end
@@ -0,0 +1,3 @@
1
+ class Subscription < ActiveRecord::Base
2
+ belongs_to :show
3
+ end
@@ -0,0 +1,11 @@
1
+ class SubscriptionCreator < ActiveCucumber::Creator
2
+
3
+ def value_for_show show_name
4
+ Show.find_by(name: show_name) || FactoryGirl.create(:show, name: show_name)
5
+ end
6
+
7
+ def value_for_subscriber subscriber_name
8
+ subscriber_name == 'me' ? @current_user : subscriber_name
9
+ end
10
+
11
+ end
@@ -0,0 +1,7 @@
1
+ class SubscriptionCucumberator < ActiveCucumber::Cucumberator
2
+
3
+ def value_for_show
4
+ show.try :name
5
+ end
6
+
7
+ end
@@ -8,16 +8,16 @@ module ActiveCucumber
8
8
 
9
9
  # Creates entries of the given ActiveRecord class
10
10
  # specified by the given horizontal Cucumber table
11
- def self.create_many activerecord_class, cucumber_table
12
- builder = ActiveRecordBuilder.new activerecord_class
11
+ def self.create_many activerecord_class, cucumber_table, context: {}
12
+ builder = ActiveRecordBuilder.new activerecord_class, context
13
13
  builder.create_many ActiveCucumber.horizontal_table(cucumber_table)
14
14
  end
15
15
 
16
16
 
17
17
  # Creates an entry of the given ActiveRecord class
18
18
  # specified by the given vertical Cucumber table
19
- def self.create_one activerecord_class, cucumber_table
20
- builder = ActiveRecordBuilder.new activerecord_class
19
+ def self.create_one activerecord_class, cucumber_table, context: {}
20
+ builder = ActiveRecordBuilder.new activerecord_class, context
21
21
  builder.create_record ActiveCucumber.vertical_table(cucumber_table)
22
22
  end
23
23
 
@@ -3,9 +3,10 @@ module ActiveCucumber
3
3
  # Creates ActiveRecord entries with data from given Cucumber tables.
4
4
  class ActiveRecordBuilder
5
5
 
6
- def initialize activerecord_class
6
+ def initialize activerecord_class, context
7
7
  @clazz = activerecord_class
8
8
  @creator_class = creator_class
9
+ @context = context
9
10
  end
10
11
 
11
12
 
@@ -19,7 +20,7 @@ module ActiveCucumber
19
20
 
20
21
  # Creates a new record with the given attributes in the database
21
22
  def create_record attributes
22
- creator = @creator_class.new attributes
23
+ creator = @creator_class.new attributes, @context
23
24
  FactoryGirl.create @clazz, creator.factorygirl_attributes
24
25
  end
25
26
 
@@ -7,8 +7,11 @@ module ActiveCucumber
7
7
 
8
8
  include FactoryGirl::Syntax::Methods
9
9
 
10
- def initialize attributes
10
+ def initialize attributes, context
11
11
  @attributes = attributes
12
+ context.each do |key, value|
13
+ instance_variable_set "@#{key}", value
14
+ end
12
15
  end
13
16
 
14
17
  # Returns the FactoryGirl version of this Creator's attributes
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_cucumber
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Goslar
@@ -223,6 +223,9 @@ files:
223
223
  - features/support/genre.rb
224
224
  - features/support/show.rb
225
225
  - features/support/show_cucumberator.rb
226
+ - features/support/subscription.rb
227
+ - features/support/subscription_creator.rb
228
+ - features/support/subscription_cucumberator.rb
226
229
  - lib/active_cucumber.rb
227
230
  - lib/active_cucumber/active_record_builder.rb
228
231
  - lib/active_cucumber/creator.rb