pickle 0.4.11 → 0.5.0
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/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Gemfile.lock.development +91 -94
- data/History.txt +8 -1
- data/README.rdoc +8 -9
- data/Rakefile.d/cucumber.rake +10 -9
- data/features/app/blueprints.rb +1 -6
- data/features/app/factories.rb +17 -15
- data/features/step_definitions/email_steps.rb +10 -10
- data/features/step_definitions/fork_steps.rb +2 -2
- data/features/step_definitions/generator_steps.rb +15 -9
- data/features/step_definitions/path_steps.rb +3 -3
- data/features/step_definitions/pickle_steps.rb +19 -19
- data/features/step_definitions/raise_error_steps.rb +3 -3
- data/features/support/pickle.rb +0 -1
- data/lib/generators/pickle_generator.rb +1 -26
- data/lib/pickle/adapter.rb +4 -10
- data/lib/pickle/version.rb +2 -2
- data/pickle.gemspec +7 -6
- data/rails_generators/pickle/pickle_generator.rb +2 -4
- data/rails_generators/pickle/templates/email_steps.rb +10 -10
- data/rails_generators/pickle/templates/pickle.rb +0 -1
- data/rails_generators/pickle/templates/pickle_steps.rb +19 -19
- data/spec/pickle/adapter_spec.rb +39 -39
- data/spec/pickle/config_spec.rb +29 -29
- data/spec/pickle/email/parser_spec.rb +9 -9
- data/spec/pickle/email_spec.rb +38 -38
- data/spec/pickle/parser/matchers_spec.rb +8 -8
- data/spec/pickle/parser_spec.rb +34 -34
- data/spec/pickle/path_spec.rb +33 -33
- data/spec/pickle/session_spec.rb +87 -87
- data/spec/pickle_spec.rb +4 -4
- data/spec/spec_helper.rb +73 -3
- metadata +55 -79
@@ -8,11 +8,15 @@ After('@gen') do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
Given(/^cucumber has been freshly generated$/) do
|
11
|
-
|
11
|
+
Bundler.with_clean_env do
|
12
|
+
`cd #{Rails.root}; rails g cucumber:install -f --capybara`
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
16
|
Given(/^pickle path email has been freshly generated$/) do
|
15
|
-
|
17
|
+
Bundler.with_clean_env do
|
18
|
+
`cd #{Rails.root}; rails g pickle paths email -f`
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
Given(/^env\.rb already requires (.+)$/) do |file|
|
@@ -22,25 +26,27 @@ Given(/^env\.rb already requires (.+)$/) do |file|
|
|
22
26
|
end
|
23
27
|
|
24
28
|
When(/^I run "(.*)"$/) do |command|
|
25
|
-
|
29
|
+
Bundler.with_clean_env do
|
30
|
+
@output = `cd #{Rails.root}; #{command}`
|
31
|
+
end
|
26
32
|
end
|
27
33
|
|
28
34
|
Then(/^I should see "(.*)"$/) do |text|
|
29
|
-
@output.
|
35
|
+
expect(@output).to include(text)
|
30
36
|
end
|
31
37
|
|
32
38
|
Then(/^the file (.+?) should exist$/) do |file|
|
33
|
-
File.exist?("#{Rails.root}/#{file}").
|
39
|
+
expect(File.exist?("#{Rails.root}/#{file}")).to eq(true)
|
34
40
|
end
|
35
41
|
|
36
42
|
Then(/^the file (.+?) should match \/(.*?)\/$/) do |file, regexp|
|
37
|
-
File.read("#{Rails.root}/#{file}").
|
43
|
+
expect(File.read("#{Rails.root}/#{file}")).to match(/#{regexp}/m)
|
38
44
|
end
|
39
45
|
|
40
46
|
Then(/^the file (.+?) should not match \/(.*?)\/$/) do |file, regexp|
|
41
|
-
File.read("#{Rails.root}/#{file}").
|
47
|
+
expect(File.read("#{Rails.root}/#{file}")).not_to match(/#{regexp}/m)
|
42
48
|
end
|
43
49
|
|
44
50
|
Then /^the file ([^ ]+) should be identical to the local (.+)$/ do |generated_file, source_file|
|
45
|
-
File.read("#{Rails.root}/#{generated_file}").
|
46
|
-
end
|
51
|
+
expect(File.read("#{Rails.root}/#{generated_file}")).to eq(File.read("#{File.dirname(__FILE__)}/../#{source_file}"))
|
52
|
+
end
|
@@ -2,7 +2,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "pat
|
|
2
2
|
|
3
3
|
Then(/^(.+?) should match route \/(.+?)$/) do |page, route|
|
4
4
|
regexp = route.gsub(/:(\w*?)id/,'\d+')
|
5
|
-
path_to(page).
|
5
|
+
expect(path_to(page)).to match(/#{regexp}/)
|
6
6
|
end
|
7
7
|
|
8
8
|
When(/^I go to (.+)$/) do |page|
|
@@ -10,5 +10,5 @@ When(/^I go to (.+)$/) do |page|
|
|
10
10
|
end
|
11
11
|
|
12
12
|
Then(/^I should be at (.+)$/) do |page|
|
13
|
-
current_url.
|
14
|
-
end
|
13
|
+
expect(current_url).to match(/#{path_to(page)}/)
|
14
|
+
end
|
@@ -22,79 +22,79 @@ end
|
|
22
22
|
|
23
23
|
# not find a model
|
24
24
|
Then(/^#{capture_model} should not exist(?: with #{capture_fields})?$/) do |name, fields|
|
25
|
-
find_model(name, fields).
|
25
|
+
expect(find_model(name, fields)).to be_nil
|
26
26
|
end
|
27
27
|
|
28
28
|
# find models with a table
|
29
29
|
Then(/^the following #{capture_plural_factory} should exists?:?$/) do |plural_factory, table|
|
30
|
-
find_models_from_table(plural_factory, table).
|
30
|
+
expect(find_models_from_table(plural_factory, table)).not_to be_any(&:nil?)
|
31
31
|
end
|
32
32
|
|
33
33
|
# find exactly n models
|
34
34
|
Then(/^(\d+) #{capture_plural_factory} should exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
|
35
|
-
find_models(plural_factory.singularize, fields).size.
|
35
|
+
expect(find_models(plural_factory.singularize, fields).size).to eq(count.to_i)
|
36
36
|
end
|
37
37
|
|
38
38
|
# assert equality of models
|
39
39
|
Then(/^#{capture_model} should be #{capture_model}$/) do |a, b|
|
40
|
-
model!(a).
|
40
|
+
expect(model!(a)).to eq(model!(b))
|
41
41
|
end
|
42
42
|
|
43
43
|
# assert model is in another model's has_many assoc
|
44
44
|
Then(/^#{capture_model} should be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
|
45
|
-
model!(owner).send(association).
|
45
|
+
expect(model!(owner).send(association)).to include(model!(target))
|
46
46
|
end
|
47
47
|
|
48
48
|
# assert model is not in another model's has_many assoc
|
49
49
|
Then(/^#{capture_model} should not be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
|
50
|
-
model!(owner).send(association).
|
50
|
+
expect(model!(owner).send(association)).not_to include(model!(target))
|
51
51
|
end
|
52
52
|
|
53
53
|
# assert model is another model's has_one/belongs_to assoc
|
54
54
|
Then(/^#{capture_model} should be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
|
55
|
-
model!(owner).send(association).
|
55
|
+
expect(model!(owner).send(association)).to eq(model!(target))
|
56
56
|
end
|
57
57
|
|
58
58
|
# assert model is not another model's has_one/belongs_to assoc
|
59
59
|
Then(/^#{capture_model} should not be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
|
60
|
-
model!(owner).send(association).
|
60
|
+
expect(model!(owner).send(association)).not_to eq(model!(target))
|
61
61
|
end
|
62
62
|
|
63
63
|
# assert model.predicate?
|
64
64
|
Then(/^#{capture_model} should (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
|
65
65
|
if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
|
66
|
-
model!(name).
|
66
|
+
expect(model!(name)).to send("have_#{predicate.gsub(' ', '_')}")
|
67
67
|
else
|
68
|
-
model!(name).
|
68
|
+
expect(model!(name)).to send("be_#{predicate.gsub(' ', '_')}")
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
# assert not model.predicate?
|
73
73
|
Then(/^#{capture_model} should not (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
|
74
74
|
if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
|
75
|
-
model!(name).
|
75
|
+
expect(model!(name)).not_to send("have_#{predicate.gsub(' ', '_')}")
|
76
76
|
else
|
77
|
-
model!(name).
|
77
|
+
expect(model!(name)).not_to send("be_#{predicate.gsub(' ', '_')}")
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
# model.attribute.
|
82
|
-
# model.attribute.
|
81
|
+
# expect(model.attribute).to eq(value)
|
82
|
+
# expect(model.attribute).not_to eq(value)
|
83
83
|
Then(/^#{capture_model}'s (\w+) (should(?: not)?) be #{capture_value}$/) do |name, attribute, expectation, expected|
|
84
84
|
actual_value = model(name).send(attribute)
|
85
|
-
expectation = expectation.gsub(
|
85
|
+
expectation = expectation.gsub("should", "to").gsub(" ", "_")
|
86
86
|
|
87
87
|
case expected
|
88
88
|
when 'nil', 'true', 'false'
|
89
|
-
actual_value.send(expectation,
|
89
|
+
expect(actual_value).send(expectation, eq(eval(expected)))
|
90
90
|
when /^[+-]?[0-9_]+(\.\d+)?$/
|
91
|
-
actual_value.send(expectation,
|
91
|
+
expect(actual_value).send(expectation, eq(expected.to_f))
|
92
92
|
else
|
93
|
-
actual_value.to_s.send(expectation,
|
93
|
+
expect(actual_value.to_s).send(expectation, eq(eval(expected)))
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
# assert size of association
|
98
98
|
Then /^#{capture_model} should have (\d+) (\w+)$/ do |name, size, association|
|
99
|
-
model!(name).send(association).size.
|
99
|
+
expect(model!(name).send(association).size).to eq(size.to_i)
|
100
100
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Then /^the following should raise an? ([\w:]+):$/ do |error, step|
|
2
|
-
|
2
|
+
expect { steps step }.to raise_error(error.constantize)
|
3
3
|
end
|
4
4
|
|
5
5
|
Then /^the following should raise an? ([\w:]+) with "([^"]*)":$/ do |error, message, step|
|
6
|
-
|
7
|
-
end
|
6
|
+
expect { steps step }.to raise_error(error.constantize, message)
|
7
|
+
end
|
data/features/support/pickle.rb
CHANGED
@@ -6,7 +6,6 @@
|
|
6
6
|
#
|
7
7
|
# require 'machinist/active_record' # or your chosen adaptor
|
8
8
|
# require File.dirname(__FILE__) + '/../../spec/blueprints' # or wherever your blueprints are
|
9
|
-
# Before { Sham.reset } # to reset Sham's seed between scenarios so each run has same random sequences
|
10
9
|
#
|
11
10
|
# For FactoryGirl add: features/support/factory_girl.rb
|
12
11
|
#
|
@@ -9,15 +9,6 @@ class PickleGenerator < Rails::Generators::Base
|
|
9
9
|
class_option :paths, :desc => "Generate features/support/paths.rb file.", :type => :boolean
|
10
10
|
class_option :email, :desc => "Generate features/step_definitions/email_steps.rb file", :type => :boolean
|
11
11
|
|
12
|
-
def initialize(args = [], options = {}, config = {})
|
13
|
-
super
|
14
|
-
|
15
|
-
if self.options.paths? && !File.exists?("features/support/paths.rb")
|
16
|
-
say "features/support/paths.rb not found, is your cucumber up to date?", :red
|
17
|
-
exit
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
12
|
def create_directories
|
22
13
|
empty_directory "features/step_definitions"
|
23
14
|
empty_directory "features/support"
|
@@ -30,15 +21,7 @@ class PickleGenerator < Rails::Generators::Base
|
|
30
21
|
|
31
22
|
def copy_paths_file
|
32
23
|
return unless options.paths?
|
33
|
-
|
34
|
-
current_paths = File.read("features/support/paths.rb")
|
35
|
-
unless current_paths.include?('#{capture_model}')
|
36
|
-
if current_paths =~ /^(.*)(\n\s+else\n\s+raise "Can't find.*".*$)/m
|
37
|
-
@current_paths_header = $1
|
38
|
-
@current_paths_footer = $2
|
39
|
-
end
|
40
|
-
template "paths.rb", "features/support/paths.rb"
|
41
|
-
end
|
24
|
+
template "paths.rb", "features/support/paths.rb"
|
42
25
|
end
|
43
26
|
|
44
27
|
def copy_email_steps_file
|
@@ -58,12 +41,4 @@ class PickleGenerator < Rails::Generators::Base
|
|
58
41
|
def pickle_email
|
59
42
|
options.email?
|
60
43
|
end
|
61
|
-
|
62
|
-
def current_paths_header
|
63
|
-
@current_paths_header
|
64
|
-
end
|
65
|
-
|
66
|
-
def current_paths_footer
|
67
|
-
@current_paths_footer
|
68
|
-
end
|
69
44
|
end
|
data/lib/pickle/adapter.rb
CHANGED
@@ -95,11 +95,7 @@ module Pickle
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def create(attrs = {})
|
98
|
-
|
99
|
-
@klass.send(:make!, @blueprint, attrs)
|
100
|
-
else
|
101
|
-
@klass.send(:make, @blueprint, attrs)
|
102
|
-
end
|
98
|
+
@klass.send(:make!, @blueprint, attrs)
|
103
99
|
end
|
104
100
|
end
|
105
101
|
|
@@ -136,8 +132,8 @@ module Pickle
|
|
136
132
|
class Fabrication < Adapter
|
137
133
|
def self.factories
|
138
134
|
if defined? ::Fabrication
|
139
|
-
::Fabrication
|
140
|
-
::Fabrication
|
135
|
+
::Fabrication.manager.load_definitions if ::Fabrication.manager.schematics.empty?
|
136
|
+
::Fabrication.manager.schematics.map { |name, klass| new([name, klass]) }
|
141
137
|
else
|
142
138
|
[]
|
143
139
|
end
|
@@ -151,9 +147,7 @@ module Pickle
|
|
151
147
|
|
152
148
|
def create(attrs = {})
|
153
149
|
if defined? ::Fabrication
|
154
|
-
|
155
|
-
:save => true
|
156
|
-
}, attrs)
|
150
|
+
Fabricate(@name.to_sym, attrs)
|
157
151
|
end
|
158
152
|
end
|
159
153
|
end
|
data/lib/pickle/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Pickle
|
2
|
-
VERSION = "0.
|
3
|
-
end
|
2
|
+
VERSION = "0.5.0"
|
3
|
+
end
|
data/pickle.gemspec
CHANGED
@@ -5,11 +5,12 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.name = "pickle"
|
6
6
|
s.version = Pickle::VERSION.dup
|
7
7
|
s.platform = Gem::Platform::RUBY
|
8
|
-
s.
|
8
|
+
s.licenses = ["MIT"]
|
9
|
+
s.authors = ["Ian White", "James Le Cuirot", "Niklas Hofer"]
|
9
10
|
s.description = "Easy model creation and reference in your cucumber features"
|
10
11
|
s.summary = "Easy model creation and reference in your cucumber features."
|
11
|
-
s.email = "ian.w.white@gmail.com"
|
12
|
-
s.homepage = "
|
12
|
+
s.email = ["ian.w.white@gmail.com", "chewi@aura-online.co.uk", "niklas+dev@lanpartei.de"]
|
13
|
+
s.homepage = "https://github.com/ianwhite/pickle"
|
13
14
|
|
14
15
|
s.rubyforge_project = "pickle"
|
15
16
|
s.required_rubygems_version = ">= 1.3.6"
|
@@ -25,12 +26,12 @@ Gem::Specification.new do |s|
|
|
25
26
|
s.add_development_dependency "bundler"
|
26
27
|
s.add_development_dependency "git"
|
27
28
|
s.add_development_dependency "yard"
|
28
|
-
s.add_development_dependency "rspec-rails", "~>
|
29
|
+
s.add_development_dependency "rspec-rails", "~>3.0"
|
29
30
|
s.add_development_dependency "rails", "~>3.1.0"
|
30
31
|
s.add_development_dependency "cucumber-rails"
|
31
32
|
s.add_development_dependency "factory_girl"
|
32
|
-
s.add_development_dependency "fabrication"
|
33
|
-
s.add_development_dependency "machinist"
|
33
|
+
s.add_development_dependency "fabrication", '~> 2.0'
|
34
|
+
s.add_development_dependency "machinist", "~>2.0"
|
34
35
|
s.add_development_dependency "database_cleaner"
|
35
36
|
s.add_development_dependency "capybara"
|
36
37
|
s.add_development_dependency "sqlite3-ruby"
|
@@ -2,9 +2,7 @@ class PickleGenerator < Rails::Generator::Base
|
|
2
2
|
def initialize(args, options)
|
3
3
|
super(args, options)
|
4
4
|
@generate_email_steps = args.include?('email')
|
5
|
-
|
6
|
-
File.exists?('features/support/paths.rb') or raise "features/support/paths.rb not found, is your cucumber up to date?"
|
7
|
-
end
|
5
|
+
@generate_path_steps = args.include?('path')
|
8
6
|
end
|
9
7
|
|
10
8
|
def manifest
|
@@ -30,4 +28,4 @@ class PickleGenerator < Rails::Generator::Base
|
|
30
28
|
m.template 'pickle.rb', File.join('features/support', 'pickle.rb'), :assigns => pickle_assigns
|
31
29
|
end
|
32
30
|
end
|
33
|
-
end
|
31
|
+
end
|
@@ -15,7 +15,7 @@ Given(/^all emails? (?:have|has) been delivered$/) do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
Given(/^(\d)+ emails? should be delivered$/) do |count|
|
18
|
-
emails.size.
|
18
|
+
expect(emails.size).to eq(count.to_i)
|
19
19
|
end
|
20
20
|
|
21
21
|
When(/^(?:I|they) follow "([^"]*?)" in #{capture_email}$/) do |link, email_ref|
|
@@ -27,37 +27,37 @@ When(/^(?:I|they) click the first link in #{capture_email}$/) do |email_ref|
|
|
27
27
|
end
|
28
28
|
|
29
29
|
Then(/^(\d)+ emails? should be delivered to (.*)$/) do |count, to|
|
30
|
-
emails("to: \"#{email_for(to)}\"").size.
|
30
|
+
expect(emails("to: \"#{email_for(to)}\"").size).to eq(count.to_i)
|
31
31
|
end
|
32
32
|
|
33
33
|
Then(/^(\d)+ emails? should be delivered with #{capture_fields}$/) do |count, fields|
|
34
|
-
emails(fields).size.
|
34
|
+
expect(emails(fields).size).to eq(count.to_i)
|
35
35
|
end
|
36
36
|
|
37
37
|
Then(/^#{capture_email} should be delivered to (.+)$/) do |email_ref, to|
|
38
|
-
email(email_ref, "to: \"#{email_for(to)}\"").
|
38
|
+
expect(email(email_ref, "to: \"#{email_for(to)}\"")).not_to be_nil
|
39
39
|
end
|
40
40
|
|
41
41
|
Then(/^#{capture_email} should not be delivered to (.+)$/) do |email_ref, to|
|
42
|
-
email(email_ref, "to: \"#{email_for(to)}\"").
|
42
|
+
expect(email(email_ref, "to: \"#{email_for(to)}\"")).to be_nil
|
43
43
|
end
|
44
44
|
|
45
45
|
Then(/^#{capture_email} should have #{capture_fields}$/) do |email_ref, fields|
|
46
|
-
email(email_ref, fields).
|
46
|
+
expect(email(email_ref, fields)).not_to be_nil
|
47
47
|
end
|
48
48
|
|
49
49
|
Then(/^#{capture_email} should contain "(.*)"$/) do |email_ref, text|
|
50
|
-
email(email_ref).body.
|
50
|
+
expect(email(email_ref).body).to match(/#{text}/)
|
51
51
|
end
|
52
52
|
|
53
53
|
Then(/^#{capture_email} should not contain "(.*)"$/) do |email_ref, text|
|
54
|
-
email(email_ref).body.
|
54
|
+
expect(email(email_ref).body).not_to match(/#{text}/)
|
55
55
|
end
|
56
56
|
|
57
57
|
Then(/^#{capture_email} should link to (.+)$/) do |email_ref, page|
|
58
|
-
email(email_ref).body.
|
58
|
+
expect(email(email_ref).body).to match(/#{path_to(page)}/)
|
59
59
|
end
|
60
60
|
|
61
61
|
Then(/^show me the emails?$/) do
|
62
62
|
save_and_open_emails
|
63
|
-
end
|
63
|
+
end
|
@@ -6,7 +6,6 @@
|
|
6
6
|
#
|
7
7
|
# require 'machinist/active_record' # or your chosen adaptor
|
8
8
|
# require File.dirname(__FILE__) + '/../../spec/blueprints' # or wherever your blueprints are
|
9
|
-
# Before { Sham.reset } # to reset Sham's seed between scenarios so each run has same random sequences
|
10
9
|
#
|
11
10
|
# For FactoryGirl add: features/support/factory_girl.rb
|
12
11
|
#
|
@@ -22,79 +22,79 @@ end
|
|
22
22
|
|
23
23
|
# not find a model
|
24
24
|
Then(/^#{capture_model} should not exist(?: with #{capture_fields})?$/) do |name, fields|
|
25
|
-
find_model(name, fields).
|
25
|
+
expect(find_model(name, fields)).to be_nil
|
26
26
|
end
|
27
27
|
|
28
28
|
# find models with a table
|
29
29
|
Then(/^the following #{capture_plural_factory} should exists?:?$/) do |plural_factory, table|
|
30
|
-
find_models_from_table(plural_factory, table).
|
30
|
+
expect(find_models_from_table(plural_factory, table)).not_to be_any(&:nil?)
|
31
31
|
end
|
32
32
|
|
33
33
|
# find exactly n models
|
34
34
|
Then(/^(\d+) #{capture_plural_factory} should exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
|
35
|
-
find_models(plural_factory.singularize, fields).size.
|
35
|
+
expect(find_models(plural_factory.singularize, fields).size).to eq(count.to_i)
|
36
36
|
end
|
37
37
|
|
38
38
|
# assert equality of models
|
39
39
|
Then(/^#{capture_model} should be #{capture_model}$/) do |a, b|
|
40
|
-
model!(a).
|
40
|
+
expect(model!(a)).to eq(model!(b))
|
41
41
|
end
|
42
42
|
|
43
43
|
# assert model is in another model's has_many assoc
|
44
44
|
Then(/^#{capture_model} should be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
|
45
|
-
model!(owner).send(association).
|
45
|
+
expect(model!(owner).send(association)).to include(model!(target))
|
46
46
|
end
|
47
47
|
|
48
48
|
# assert model is not in another model's has_many assoc
|
49
49
|
Then(/^#{capture_model} should not be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
|
50
|
-
model!(owner).send(association).
|
50
|
+
expect(model!(owner).send(association)).not_to include(model!(target))
|
51
51
|
end
|
52
52
|
|
53
53
|
# assert model is another model's has_one/belongs_to assoc
|
54
54
|
Then(/^#{capture_model} should be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
|
55
|
-
model!(owner).send(association).
|
55
|
+
expect(model!(owner).send(association)).to eq(model!(target))
|
56
56
|
end
|
57
57
|
|
58
58
|
# assert model is not another model's has_one/belongs_to assoc
|
59
59
|
Then(/^#{capture_model} should not be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
|
60
|
-
model!(owner).send(association).
|
60
|
+
expect(model!(owner).send(association)).not_to eq(model!(target))
|
61
61
|
end
|
62
62
|
|
63
63
|
# assert model.predicate?
|
64
64
|
Then(/^#{capture_model} should (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
|
65
65
|
if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
|
66
|
-
model!(name).
|
66
|
+
expect(model!(name)).to send("have_#{predicate.gsub(' ', '_')}")
|
67
67
|
else
|
68
|
-
model!(name).
|
68
|
+
expect(model!(name)).to send("be_#{predicate.gsub(' ', '_')}")
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
# assert not model.predicate?
|
73
73
|
Then(/^#{capture_model} should not (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
|
74
74
|
if model!(name).respond_to?("has_#{predicate.gsub(' ', '_')}")
|
75
|
-
model!(name).
|
75
|
+
expect(model!(name)).not_to send("have_#{predicate.gsub(' ', '_')}")
|
76
76
|
else
|
77
|
-
model!(name).
|
77
|
+
expect(model!(name)).not_to send("be_#{predicate.gsub(' ', '_')}")
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
# model.attribute.
|
82
|
-
# model.attribute.
|
81
|
+
# expect(model.attribute).to eq(value)
|
82
|
+
# expect(model.attribute).not_to eq(value)
|
83
83
|
Then(/^#{capture_model}'s (\w+) (should(?: not)?) be #{capture_value}$/) do |name, attribute, expectation, expected|
|
84
84
|
actual_value = model(name).send(attribute)
|
85
|
-
expectation = expectation.gsub(
|
85
|
+
expectation = expectation.gsub("should", "to").gsub(" ", "_")
|
86
86
|
|
87
87
|
case expected
|
88
88
|
when 'nil', 'true', 'false'
|
89
|
-
actual_value.send(expectation,
|
89
|
+
expect(actual_value).send(expectation, eq(eval(expected)))
|
90
90
|
when /^[+-]?[0-9_]+(\.\d+)?$/
|
91
|
-
actual_value.send(expectation,
|
91
|
+
expect(actual_value).send(expectation, eq(expected.to_f))
|
92
92
|
else
|
93
|
-
actual_value.to_s.send(expectation,
|
93
|
+
expect(actual_value.to_s).send(expectation, eq(eval(expected)))
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
# assert size of association
|
98
98
|
Then /^#{capture_model} should have (\d+) (\w+)$/ do |name, size, association|
|
99
|
-
model!(name).send(association).size.
|
99
|
+
expect(model!(name).send(association).size).to eq(size.to_i)
|
100
100
|
end
|