spbtv_pickle 0.5.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 +17 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Gemfile +3 -0
- data/Gemfile.lock.development +158 -0
- data/History.txt +499 -0
- data/License.txt +20 -0
- data/README.md +566 -0
- data/Rakefile +20 -0
- data/Rakefile.d/cucumber.rake +27 -0
- data/Rakefile.d/release.rake +44 -0
- data/Rakefile.d/rspec.rake +3 -0
- data/Rakefile.d/yard.rake +5 -0
- data/Todo.txt +3 -0
- data/autotest/discover.rb +9 -0
- data/features/app/app.rb +128 -0
- data/features/app/blueprints.rb +6 -0
- data/features/app/fabricators.rb +6 -0
- data/features/app/factories.rb +25 -0
- data/features/app/views/notifier/email.erb +1 -0
- data/features/app/views/notifier/user_email.erb +6 -0
- data/features/email/email.feature +64 -0
- data/features/generator/generators.feature +59 -0
- data/features/path/models_page.feature +44 -0
- data/features/path/named_route_page.feature +10 -0
- data/features/pickle/create_from_active_record.feature +83 -0
- data/features/pickle/create_from_fabrication.feature +46 -0
- data/features/pickle/create_from_factory_girl.feature +66 -0
- data/features/pickle/create_from_machinist.feature +46 -0
- data/features/step_definitions/email_steps.rb +1 -0
- data/features/step_definitions/extra_email_steps.rb +12 -0
- data/features/step_definitions/fork_steps.rb +4 -0
- data/features/step_definitions/generator_steps.rb +52 -0
- data/features/step_definitions/path_steps.rb +14 -0
- data/features/step_definitions/pickle_steps.rb +1 -0
- data/features/step_definitions/raise_error_steps.rb +7 -0
- data/features/support/email.rb +1 -0
- data/features/support/env.rb +14 -0
- data/features/support/paths.rb +47 -0
- data/features/support/pickle.rb +27 -0
- data/features/support/pickle_app.rb +4 -0
- data/init.rb +0 -0
- data/lib/generators/pickle_generator.rb +44 -0
- data/lib/pickle.rb +26 -0
- data/lib/pickle/adapter.rb +183 -0
- data/lib/pickle/adapters/active_record.rb +67 -0
- data/lib/pickle/adapters/data_mapper.rb +42 -0
- data/lib/pickle/adapters/mongoid.rb +54 -0
- data/lib/pickle/config.rb +49 -0
- data/lib/pickle/email.rb +87 -0
- data/lib/pickle/email/parser.rb +18 -0
- data/lib/pickle/email/world.rb +13 -0
- data/lib/pickle/parser.rb +65 -0
- data/lib/pickle/parser/matchers.rb +87 -0
- data/lib/pickle/path.rb +45 -0
- data/lib/pickle/path/world.rb +5 -0
- data/lib/pickle/session.rb +244 -0
- data/lib/pickle/session/parser.rb +34 -0
- data/lib/pickle/version.rb +3 -0
- data/lib/pickle/world.rb +14 -0
- data/lib/spbtv_pickle.rb +1 -0
- data/rails_generators/pickle/pickle_generator.rb +31 -0
- data/rails_generators/pickle/templates/email.rb +21 -0
- data/rails_generators/pickle/templates/email_steps.rb +65 -0
- data/rails_generators/pickle/templates/paths.rb +47 -0
- data/rails_generators/pickle/templates/pickle.rb +29 -0
- data/rails_generators/pickle/templates/pickle_steps.rb +105 -0
- data/spbtv_pickle.gemspec +38 -0
- data/spec/pickle/adapter_spec.rb +203 -0
- data/spec/pickle/config_spec.rb +112 -0
- data/spec/pickle/email/parser_spec.rb +51 -0
- data/spec/pickle/email_spec.rb +187 -0
- data/spec/pickle/parser/matchers_spec.rb +70 -0
- data/spec/pickle/parser_spec.rb +165 -0
- data/spec/pickle/path_spec.rb +120 -0
- data/spec/pickle/session_spec.rb +448 -0
- data/spec/pickle_spec.rb +24 -0
- data/spec/spec_helper.rb +78 -0
- metadata +370 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Pickle
|
|
2
|
+
module Session
|
|
3
|
+
# add ability to parse model names as fields, using a session
|
|
4
|
+
module Parser
|
|
5
|
+
def self.included(parser_class)
|
|
6
|
+
parser_class.alias_method_chain :parse_field, :model
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
attr_accessor :session
|
|
10
|
+
|
|
11
|
+
def match_field
|
|
12
|
+
"(?:\\w+: (?:#{match_model}|#{match_value}))"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def parse_field_with_model(field)
|
|
16
|
+
if session && field =~ /^(\w+): #{capture_model}$/
|
|
17
|
+
{$1 => session.model!($2)}
|
|
18
|
+
else
|
|
19
|
+
parse_field_without_model(field)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def parse_hash(hash)
|
|
24
|
+
hash.inject({}) do |parsed, (key, val)|
|
|
25
|
+
if session && val =~ /^#{capture_model}$/
|
|
26
|
+
parsed.merge(key => session.model($1))
|
|
27
|
+
else
|
|
28
|
+
parsed.merge(key => val)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/pickle/world.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'pickle'
|
|
2
|
+
|
|
3
|
+
# auto require for active record, datamapper and mongoid
|
|
4
|
+
require 'pickle/adapters/active_record' if defined?(ActiveRecord::Base)
|
|
5
|
+
require 'pickle/adapters/data_mapper' if defined?(DataMapper::Resource)
|
|
6
|
+
require 'pickle/adapters/mongoid' if defined?(Mongoid::Document)
|
|
7
|
+
|
|
8
|
+
# make cucumber world pickle aware
|
|
9
|
+
World(Pickle::Session)
|
|
10
|
+
|
|
11
|
+
# shortcuts to regexps for use in step definition regexps
|
|
12
|
+
class << self
|
|
13
|
+
delegate :capture_model, :capture_fields, :capture_factory, :capture_plural_factory, :capture_predicate, :capture_value, :to => 'Pickle.parser'
|
|
14
|
+
end
|
data/lib/spbtv_pickle.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require_relative 'pickle'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
class PickleGenerator < Rails::Generator::Base
|
|
2
|
+
def initialize(args, options)
|
|
3
|
+
super(args, options)
|
|
4
|
+
@generate_email_steps = args.include?('email')
|
|
5
|
+
@generate_path_steps = args.include?('path')
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def manifest
|
|
9
|
+
record do |m|
|
|
10
|
+
m.directory File.join('features/step_definitions')
|
|
11
|
+
m.directory File.join('features/support')
|
|
12
|
+
|
|
13
|
+
current_pickle = File.exists?('features/support/pickle.rb') ? File.read('features/support/pickle.rb') : ''
|
|
14
|
+
pickle_assigns = {:pickle_path => false, :pickle_email => false}
|
|
15
|
+
|
|
16
|
+
if @generate_path_steps
|
|
17
|
+
pickle_assigns[:pickle_path] = true
|
|
18
|
+
m.template 'paths.rb', File.join('features/support', 'paths.rb')
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
if @generate_email_steps
|
|
22
|
+
pickle_assigns[:pickle_email] = true
|
|
23
|
+
m.template 'email_steps.rb', File.join('features/step_definitions', 'email_steps.rb')
|
|
24
|
+
m.template 'email.rb', File.join('features/support', 'email.rb')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
m.template 'pickle_steps.rb', File.join('features/step_definitions', 'pickle_steps.rb')
|
|
28
|
+
m.template 'pickle.rb', File.join('features/support', 'pickle.rb'), :assigns => pickle_assigns
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module EmailHelpers
|
|
2
|
+
# Maps a name to an email address. Used by email_steps
|
|
3
|
+
|
|
4
|
+
def email_for(to)
|
|
5
|
+
case to
|
|
6
|
+
|
|
7
|
+
# add your own name => email address mappings here
|
|
8
|
+
|
|
9
|
+
when /^#{capture_model}$/
|
|
10
|
+
model($1).email
|
|
11
|
+
|
|
12
|
+
when /^"(.*)"$/
|
|
13
|
+
$1
|
|
14
|
+
|
|
15
|
+
else
|
|
16
|
+
to
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
World(EmailHelpers)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# this file generated by script/generate pickle email
|
|
2
|
+
#
|
|
3
|
+
# add email mappings in features/support/email.rb
|
|
4
|
+
|
|
5
|
+
ActionMailer::Base.delivery_method = :test
|
|
6
|
+
ActionMailer::Base.perform_deliveries = true
|
|
7
|
+
|
|
8
|
+
Before do
|
|
9
|
+
ActionMailer::Base.deliveries.clear
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Clear the deliveries array, useful if your background sends email that you want to ignore
|
|
13
|
+
Given(/^all emails? (?:have|has) been delivered$/) do
|
|
14
|
+
ActionMailer::Base.deliveries.clear
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
Given(/^(\d)+ emails? should be delivered$/) do |count|
|
|
18
|
+
expect(emails.size).to eq(count.to_i)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
When(/^(?:I|they) follow "([^"]*?)" in #{capture_email}$/) do |link, email_ref|
|
|
22
|
+
visit_in_email(email(email_ref), link)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
When(/^(?:I|they) click the first link in #{capture_email}$/) do |email_ref|
|
|
26
|
+
click_first_link_in_email(email(email_ref))
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
Then(/^(\d)+ emails? should be delivered to (.*)$/) do |count, to|
|
|
30
|
+
actual = emails("to: \"#{email_for(to)}\"").size
|
|
31
|
+
expect(actual).to eq(count.to_i), "Expected #{count} emails but encountered #{actual} delivered to #{to}"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
Then(/^(\d)+ emails? should be delivered with #{capture_fields}$/) do |count, fields|
|
|
35
|
+
actual = emails(fields).size
|
|
36
|
+
expect(actual).to eq(count.to_i), "Expected #{count} emails but encountered #{actual} to be delivered with #{fields}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
Then(/^#{capture_email} should be delivered to (.+)$/) do |email_ref, to|
|
|
40
|
+
expect(email(email_ref, "to: \"#{email_for(to)}\"")).not_to be_nil, "Failed to find #{email_ref} delivered to: #{to}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
Then(/^#{capture_email} should not be delivered to (.+)$/) do |email_ref, to|
|
|
44
|
+
expect(email(email_ref, "to: \"#{email_for(to)}\"")).to be_nil, "Unexpectedly found #{email_ref} delivered to: #{to}"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
Then(/^#{capture_email} should have #{capture_fields}$/) do |email_ref, fields|
|
|
48
|
+
expect(email(email_ref, fields)).not_to be_nil, "Failed to find #{fields} in #{email_ref}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
Then(/^#{capture_email} should contain "(.*)"$/) do |email_ref, text|
|
|
52
|
+
expect(email(email_ref).body).to match(/#{text}/), "Failed to find \"#{text}\" in #{email_ref}"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
Then(/^#{capture_email} should not contain "(.*)"$/) do |email_ref, text|
|
|
56
|
+
expect(email(email_ref).body).not_to match(/#{text}/), "Unexpectedly found \"#{text}\" in #{email_ref}"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
Then(/^#{capture_email} should link to (.+)$/) do |email_ref, page|
|
|
60
|
+
expect(email(email_ref).body).to match(/#{path_to(page)}/), "Failed to find link to #{page} in #{email_ref}"
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
Then(/^show me the emails?$/) do
|
|
64
|
+
save_and_open_emails
|
|
65
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module NavigationHelpers
|
|
2
|
+
# Maps a name to a path. Used by the
|
|
3
|
+
#
|
|
4
|
+
# When /^I go to (.+)$/ do |page_name|
|
|
5
|
+
#
|
|
6
|
+
# step definition in web_steps.rb
|
|
7
|
+
#
|
|
8
|
+
def path_to(page_name)
|
|
9
|
+
case page_name
|
|
10
|
+
|
|
11
|
+
when /the home\s?page/
|
|
12
|
+
'/'
|
|
13
|
+
|
|
14
|
+
# the following are examples using path_to_pickle
|
|
15
|
+
|
|
16
|
+
when /^#{capture_model}(?:'s)? page$/ # eg. the forum's page
|
|
17
|
+
path_to_pickle $1
|
|
18
|
+
|
|
19
|
+
when /^#{capture_model}(?:'s)? #{capture_model}(?:'s)? page$/ # eg. the forum's post's page
|
|
20
|
+
path_to_pickle $1, $2
|
|
21
|
+
|
|
22
|
+
when /^#{capture_model}(?:'s)? #{capture_model}'s (.+?) page$/ # eg. the forum's post's comments page
|
|
23
|
+
path_to_pickle $1, $2, :extra => $3 # or the forum's post's edit page
|
|
24
|
+
|
|
25
|
+
when /^#{capture_model}(?:'s)? (.+?) page$/ # eg. the forum's posts page
|
|
26
|
+
path_to_pickle $1, :extra => $2 # or the forum's edit page
|
|
27
|
+
|
|
28
|
+
# Add more mappings here.
|
|
29
|
+
# Here is an example that pulls values out of the Regexp:
|
|
30
|
+
#
|
|
31
|
+
# when /^(.*)'s profile page$/i
|
|
32
|
+
# user_profile_path(User.find_by_login($1))
|
|
33
|
+
|
|
34
|
+
else
|
|
35
|
+
begin
|
|
36
|
+
page_name =~ /the (.*) page/
|
|
37
|
+
path_components = $1.split(/\s+/)
|
|
38
|
+
self.send(path_components.push('path').join('_').to_sym)
|
|
39
|
+
rescue Object => e
|
|
40
|
+
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
|
|
41
|
+
"Now, go and add a mapping in #{__FILE__}"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
World(NavigationHelpers)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# this file generated by script/generate pickle [paths] [email]
|
|
2
|
+
#
|
|
3
|
+
# Make sure that you are loading your factory of choice in your cucumber environment
|
|
4
|
+
#
|
|
5
|
+
# For machinist add: features/support/machinist.rb
|
|
6
|
+
#
|
|
7
|
+
# require 'machinist/active_record' # or your chosen adaptor
|
|
8
|
+
# require File.dirname(__FILE__) + '/../../spec/blueprints' # or wherever your blueprints are
|
|
9
|
+
#
|
|
10
|
+
# For FactoryGirl add: features/support/factory_girl.rb
|
|
11
|
+
#
|
|
12
|
+
# require 'factory_girl'
|
|
13
|
+
# require File.dirname(__FILE__) + '/../../spec/factories' # or wherever your factories are
|
|
14
|
+
#
|
|
15
|
+
# For Fabrication, just include it in the adapter list when configuring pickle as explained below.
|
|
16
|
+
#
|
|
17
|
+
# You may also need to add gem dependencies on your factory of choice in <tt>config/environments/cucumber.rb</tt>
|
|
18
|
+
|
|
19
|
+
require 'pickle/world'
|
|
20
|
+
# Example of configuring pickle:
|
|
21
|
+
#
|
|
22
|
+
# Pickle.configure do |config|
|
|
23
|
+
# config.adapters = [:machinist]
|
|
24
|
+
# config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"'
|
|
25
|
+
# end
|
|
26
|
+
<%- if pickle_path -%>require 'pickle/path/world'
|
|
27
|
+
<%- end -%>
|
|
28
|
+
<%- if pickle_email -%>require 'pickle/email/world'
|
|
29
|
+
<%- end -%>
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# this file generated by script/generate pickle
|
|
2
|
+
|
|
3
|
+
# create a model
|
|
4
|
+
Given(/^#{capture_model} exists?(?: with #{capture_fields})?$/) do |name, fields|
|
|
5
|
+
create_model(name, fields)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# create n models
|
|
9
|
+
Given(/^(\d+) #{capture_plural_factory} exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
|
|
10
|
+
create_models(count, plural_factory.singularize, fields)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# create models from a table
|
|
14
|
+
Given(/^the following #{capture_plural_factory} exists?:?$/) do |plural_factory, table|
|
|
15
|
+
create_models_from_table(plural_factory, table)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# find a model
|
|
19
|
+
Then(/^#{capture_model} should exist(?: with #{capture_fields})?$/) do |name, fields|
|
|
20
|
+
find_model!(name, fields)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# not find a model
|
|
24
|
+
Then(/^#{capture_model} should not exist(?: with #{capture_fields})?$/) do |name, fields|
|
|
25
|
+
expect(find_model(name, fields)).to be_nil
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# find models with a table
|
|
29
|
+
Then(/^the following #{capture_plural_factory} should exist:?$/) do |plural_factory, table|
|
|
30
|
+
expect(find_models_from_table(plural_factory, table)).not_to be_any(&:nil?)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# not find models with a table
|
|
34
|
+
Then(/^the following #{capture_plural_factory} should not exists?:?$/) do |plural_factory, table|
|
|
35
|
+
find_models_from_table(plural_factory, table).should be_all(&:nil?)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# find exactly n models
|
|
39
|
+
Then(/^(\d+) #{capture_plural_factory} should exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
|
|
40
|
+
expect(find_models(plural_factory.singularize, fields).size).to eq(count.to_i)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# assert equality of models
|
|
44
|
+
Then(/^#{capture_model} should be #{capture_model}$/) do |a, b|
|
|
45
|
+
expect(model!(a)).to eq(model!(b))
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# assert model is in another model's has_many assoc
|
|
49
|
+
Then(/^#{capture_model} should be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
|
|
50
|
+
expect(model!(owner).send(association)).to include(model!(target))
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# assert model is not in another model's has_many assoc
|
|
54
|
+
Then(/^#{capture_model} should not be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
|
|
55
|
+
expect(model!(owner).send(association)).not_to include(model!(target))
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# assert model is another model's has_one/belongs_to assoc
|
|
59
|
+
Then(/^#{capture_model} should be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
|
|
60
|
+
expect(model!(owner).send(association)).to eq(model!(target))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# assert model is not another model's has_one/belongs_to assoc
|
|
64
|
+
Then(/^#{capture_model} should not be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
|
|
65
|
+
expect(model!(owner).send(association)).not_to eq(model!(target))
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# assert model.predicate?
|
|
69
|
+
Then(/^#{capture_model} should (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
|
|
70
|
+
if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
|
|
71
|
+
expect(model!(name)).to send("have_#{predicate.gsub(' ', '_')}")
|
|
72
|
+
else
|
|
73
|
+
expect(model!(name)).to send("be_#{predicate.gsub(' ', '_')}")
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# assert not model.predicate?
|
|
78
|
+
Then(/^#{capture_model} should not (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
|
|
79
|
+
if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
|
|
80
|
+
expect(model!(name)).not_to send("have_#{predicate.gsub(' ', '_')}")
|
|
81
|
+
else
|
|
82
|
+
expect(model!(name)).not_to send("be_#{predicate.gsub(' ', '_')}")
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# expect(model.attribute).to eq(value)
|
|
87
|
+
# expect(model.attribute).not_to eq(value)
|
|
88
|
+
Then(/^#{capture_model}'s (\w+) (should(?: not)?) be #{capture_value}$/) do |name, attribute, expectation, expected|
|
|
89
|
+
actual_value = model(name).send(attribute)
|
|
90
|
+
expectation = expectation.gsub("should", "to").gsub(" ", "_")
|
|
91
|
+
|
|
92
|
+
case expected
|
|
93
|
+
when 'nil', 'true', 'false'
|
|
94
|
+
expect(actual_value).send(expectation, eq(eval(expected)))
|
|
95
|
+
when /^[+-]?[0-9_]+(\.\d+)?$/
|
|
96
|
+
expect(actual_value).send(expectation, eq(expected.to_f))
|
|
97
|
+
else
|
|
98
|
+
expect(actual_value.to_s).send(expectation, eq(eval(expected)))
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# assert size of association
|
|
103
|
+
Then /^#{capture_model} should have (\d+) (\w+)$/ do |name, size, association|
|
|
104
|
+
expect(model!(name).send(association).size).to eq(size.to_i)
|
|
105
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
|
2
|
+
require "pickle/version"
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |s|
|
|
5
|
+
s.name = "spbtv_pickle"
|
|
6
|
+
s.version = Pickle::VERSION.dup
|
|
7
|
+
s.platform = Gem::Platform::RUBY
|
|
8
|
+
s.licenses = ["MIT"]
|
|
9
|
+
s.authors = ["Ian White", "James Le Cuirot"]
|
|
10
|
+
s.description = "Easy model creation and reference in your cucumber features"
|
|
11
|
+
s.summary = "Easy model creation and reference in your cucumber features."
|
|
12
|
+
s.email = ["ian.w.white@gmail.com", "chewi@aura-online.co.uk"]
|
|
13
|
+
s.homepage = "https://github.com/ianwhite/pickle"
|
|
14
|
+
|
|
15
|
+
s.rubyforge_project = "pickle"
|
|
16
|
+
s.required_rubygems_version = ">= 1.3.6"
|
|
17
|
+
|
|
18
|
+
s.files = `git ls-files`.split("\n")
|
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
20
|
+
s.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
s.add_dependency "cucumber", ">=0.8"
|
|
23
|
+
s.add_dependency "rake"
|
|
24
|
+
|
|
25
|
+
s.add_development_dependency "rack"
|
|
26
|
+
s.add_development_dependency "bundler"
|
|
27
|
+
s.add_development_dependency "git"
|
|
28
|
+
s.add_development_dependency "yard"
|
|
29
|
+
s.add_development_dependency "rspec-rails", "~>3.0"
|
|
30
|
+
s.add_development_dependency "rails", "~>3.1.0"
|
|
31
|
+
s.add_development_dependency "cucumber-rails"
|
|
32
|
+
s.add_development_dependency "factory_girl"
|
|
33
|
+
s.add_development_dependency "fabrication", '~> 2.0'
|
|
34
|
+
s.add_development_dependency "machinist", "~>2.0"
|
|
35
|
+
s.add_development_dependency "database_cleaner"
|
|
36
|
+
s.add_development_dependency "capybara"
|
|
37
|
+
s.add_development_dependency "sqlite3"
|
|
38
|
+
end
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
require 'active_record'
|
|
4
|
+
require 'factory_girl'
|
|
5
|
+
require 'fabrication'
|
|
6
|
+
require 'machinist/active_record'
|
|
7
|
+
require 'pickle/adapters/active_record'
|
|
8
|
+
|
|
9
|
+
describe Pickle::Adapter do
|
|
10
|
+
it ".factories should raise NotImplementedError" do
|
|
11
|
+
expect { Pickle::Adapter.factories }.to raise_error(NotImplementedError)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "#create should raise NotImplementedError" do
|
|
15
|
+
expect { Pickle::Adapter.new.create }.to raise_error(NotImplementedError)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe "adapters: " do
|
|
19
|
+
around do |example|
|
|
20
|
+
begin
|
|
21
|
+
class One < ActiveRecord::Base; end
|
|
22
|
+
class One::Two < ActiveRecord::Base; end
|
|
23
|
+
class Three < ActiveRecord::Base; end
|
|
24
|
+
example.run
|
|
25
|
+
ensure
|
|
26
|
+
Object.send :remove_const, :One
|
|
27
|
+
Object.send :remove_const, :Three
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe 'ActiveRecord' do
|
|
32
|
+
describe 'with class stubs' do
|
|
33
|
+
before do
|
|
34
|
+
allow(Pickle::Adapter::Orm).to receive(:model_classes).and_return([One, One::Two, Three])
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it ".factories should create one for each active record class" do
|
|
38
|
+
expect(Pickle::Adapter::Orm).to receive(:new).with(One).once
|
|
39
|
+
expect(Pickle::Adapter::Orm).to receive(:new).with(One::Two).once
|
|
40
|
+
expect(Pickle::Adapter::Orm).to receive(:new).with(Three).once
|
|
41
|
+
expect(Pickle::Adapter::Orm.factories.length).to eq(3)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe ".new(Class)" do
|
|
45
|
+
before do
|
|
46
|
+
@factory = Pickle::Adapter::Orm.new(One::Two)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "should have underscored (s/_) name of Class as #name" do
|
|
50
|
+
expect(@factory.name).to eq('one_two')
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "#create(attrs) should call Class.create!(attrs)" do
|
|
54
|
+
expect(One::Two).to receive(:create!).with({:key => "val"})
|
|
55
|
+
@factory.create(:key => "val")
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe 'FactoryGirl' do
|
|
62
|
+
before do
|
|
63
|
+
allow(Pickle::Adapter::FactoryGirl).to receive(:model_classes).and_return([One, One::Two, Three])
|
|
64
|
+
|
|
65
|
+
if defined? ::FactoryGirl
|
|
66
|
+
@orig_factories = ::FactoryGirl.factories.dup
|
|
67
|
+
::FactoryGirl.factories.clear
|
|
68
|
+
::FactoryGirl::Syntax::Default::DSL.new.factory(:one, :class => One) {}
|
|
69
|
+
::FactoryGirl::Syntax::Default::DSL.new.factory(:two, :class => One::Two) {}
|
|
70
|
+
@factory1 = ::FactoryGirl.factories[:one]
|
|
71
|
+
@factory2 = ::FactoryGirl.factories[:two]
|
|
72
|
+
else
|
|
73
|
+
@orig_factories, Factory.factories = Factory.factories, {}
|
|
74
|
+
Factory.define(:one, :class => One) {}
|
|
75
|
+
Factory.define(:two, :class => One::Two) {}
|
|
76
|
+
@factory1 = Factory.factories[:one]
|
|
77
|
+
@factory2 = Factory.factories[:two]
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
after do
|
|
82
|
+
if defined? ::FactoryGirl
|
|
83
|
+
::FactoryGirl.factories.clear
|
|
84
|
+
@orig_factories.each {|f| ::FactoryGirl.factories.add(f) }
|
|
85
|
+
else
|
|
86
|
+
Factory.factories = @orig_factories
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it ".factories should create one for each factory" do
|
|
91
|
+
expect(Pickle::Adapter::FactoryGirl).to receive(:new).with(@factory1, @factory1.name).once
|
|
92
|
+
expect(Pickle::Adapter::FactoryGirl).to receive(:new).with(@factory2, @factory2.name).once
|
|
93
|
+
Pickle::Adapter::FactoryGirl.factories
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
describe ".new(factory, factory_name)" do
|
|
97
|
+
before do
|
|
98
|
+
@factory = Pickle::Adapter::FactoryGirl.new(@factory1, @factory1.name)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "should have name of factory_name" do
|
|
102
|
+
expect(@factory.name).to eq('one')
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "should have klass of build_class" do
|
|
106
|
+
expect(@factory.klass).to eq(One)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
unless defined? ::FactoryGirl
|
|
110
|
+
it "#create(attrs) should call Factory(<:key>, attrs)" do
|
|
111
|
+
expect(Factory).to receive(:create).with("one", {:key => "val"})
|
|
112
|
+
@factory.create(:key => "val")
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
describe 'Fabrication' do
|
|
119
|
+
before do
|
|
120
|
+
@schematic1 = [:one, Fabrication::Schematic::Definition.new(One)]
|
|
121
|
+
@schematic2 = [:two, Fabrication::Schematic::Definition.new(One::Two)]
|
|
122
|
+
allow(::Fabrication.manager).to receive(:schematics).and_return(Hash[[@schematic1, @schematic2]])
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it '.factories should create one for each fabricator' do
|
|
126
|
+
expect(Pickle::Adapter::Fabrication).to receive(:new).with(@schematic1)
|
|
127
|
+
expect(Pickle::Adapter::Fabrication).to receive(:new).with(@schematic2)
|
|
128
|
+
|
|
129
|
+
Pickle::Adapter::Fabrication.factories
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
describe ".new" do
|
|
133
|
+
before do
|
|
134
|
+
@factory = Pickle::Adapter::Fabrication.new(@schematic1)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it ".new should have name of schematic name" do
|
|
138
|
+
expect(@factory.name).to eq('one')
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it "should have klass of build_class" do
|
|
142
|
+
expect(@factory.klass).to eq(One)
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
describe ".create" do
|
|
147
|
+
it "returns the fabricated instance" do
|
|
148
|
+
@factory = Pickle::Adapter::Fabrication.new(@schematic1)
|
|
149
|
+
expect(Fabricate).to receive(:create).
|
|
150
|
+
with(@factory.name.to_sym, {:attribute => 'value'})
|
|
151
|
+
@factory.create({:attribute => 'value'})
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
describe 'Machinist' do
|
|
157
|
+
before do
|
|
158
|
+
allow(Pickle::Adapter::Machinist).to receive(:model_classes).and_return([One, One::Two, Three])
|
|
159
|
+
|
|
160
|
+
One.blueprint {}
|
|
161
|
+
Three.blueprint {}
|
|
162
|
+
Three.blueprint(:special) {}
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it ".factories should create one for each master blueprint, and special case" do
|
|
166
|
+
expect(Pickle::Adapter::Machinist).to receive(:new).with(One, :master).once
|
|
167
|
+
expect(Pickle::Adapter::Machinist).to receive(:new).with(Three, :master).once
|
|
168
|
+
expect(Pickle::Adapter::Machinist).to receive(:new).with(Three, :special).once
|
|
169
|
+
Pickle::Adapter::Machinist.factories
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
describe ".new(Class, :master)" do
|
|
173
|
+
before do
|
|
174
|
+
@factory = Pickle::Adapter::Machinist.new(One, :master)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it "should have underscored (s/_) name of Class as #name" do
|
|
178
|
+
expect(@factory.name).to eq('one')
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it "#create(attrs) should call Class.make!(:master, attrs)" do
|
|
182
|
+
expect(One).to receive(:make!).with(:master, {:key => "val"})
|
|
183
|
+
@factory.create(:key => "val")
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
describe ".new(Class, :special)" do
|
|
188
|
+
before do
|
|
189
|
+
@factory = Pickle::Adapter::Machinist.new(Three, :special)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it "should have 'special_<Class name>' as #name" do
|
|
193
|
+
expect(@factory.name).to eq('special_three')
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
it "#create(attrs) should call Class.make!(:special, attrs)" do
|
|
197
|
+
expect(Three).to receive(:make!).with(:special, {:key => "val"})
|
|
198
|
+
@factory.create(:key => "val")
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|