kbaum-pickle 0.2.1.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.
Files changed (64) hide show
  1. data/.gitignore +3 -0
  2. data/History.txt +239 -0
  3. data/License.txt +20 -0
  4. data/README.rdoc +246 -0
  5. data/Rakefile +110 -0
  6. data/Todo.txt +4 -0
  7. data/VERSION +1 -0
  8. data/features/app/app.rb +121 -0
  9. data/features/app/blueprints.rb +11 -0
  10. data/features/app/factories.rb +23 -0
  11. data/features/app/views/notifier/email.erb +1 -0
  12. data/features/app/views/notifier/user_email.erb +6 -0
  13. data/features/email/email.feature +39 -0
  14. data/features/generator/generators.feature +59 -0
  15. data/features/path/models_page.feature +44 -0
  16. data/features/path/named_route_page.feature +10 -0
  17. data/features/pickle/create_from_active_record.feature +49 -0
  18. data/features/pickle/create_from_factory_girl.feature +55 -0
  19. data/features/pickle/create_from_machinist.feature +38 -0
  20. data/features/step_definitions/email_steps.rb +55 -0
  21. data/features/step_definitions/extra_email_steps.rb +7 -0
  22. data/features/step_definitions/fork_steps.rb +4 -0
  23. data/features/step_definitions/generator_steps.rb +46 -0
  24. data/features/step_definitions/path_steps.rb +14 -0
  25. data/features/step_definitions/pickle_steps.rb +73 -0
  26. data/features/support/email.rb +21 -0
  27. data/features/support/env.rb +55 -0
  28. data/features/support/paths.rb +46 -0
  29. data/features/support/pickle.rb +26 -0
  30. data/features/support/pickle_app.rb +4 -0
  31. data/garlic.rb +38 -0
  32. data/init.rb +0 -0
  33. data/lib/pickle/adapter.rb +88 -0
  34. data/lib/pickle/config.rb +48 -0
  35. data/lib/pickle/email/parser.rb +18 -0
  36. data/lib/pickle/email/world.rb +13 -0
  37. data/lib/pickle/email.rb +36 -0
  38. data/lib/pickle/parser/matchers.rb +87 -0
  39. data/lib/pickle/parser.rb +65 -0
  40. data/lib/pickle/path/world.rb +5 -0
  41. data/lib/pickle/path.rb +45 -0
  42. data/lib/pickle/session/parser.rb +34 -0
  43. data/lib/pickle/session.rb +157 -0
  44. data/lib/pickle/version.rb +6 -0
  45. data/lib/pickle/world.rb +9 -0
  46. data/lib/pickle.rb +26 -0
  47. data/pickle.gemspec +110 -0
  48. data/rails_generators/pickle/pickle_generator.rb +40 -0
  49. data/rails_generators/pickle/templates/email.rb +21 -0
  50. data/rails_generators/pickle/templates/email_steps.rb +55 -0
  51. data/rails_generators/pickle/templates/paths.rb +20 -0
  52. data/rails_generators/pickle/templates/pickle.rb +28 -0
  53. data/rails_generators/pickle/templates/pickle_steps.rb +73 -0
  54. data/spec/lib/pickle_adapter_spec.rb +164 -0
  55. data/spec/lib/pickle_config_spec.rb +97 -0
  56. data/spec/lib/pickle_email_parser_spec.rb +49 -0
  57. data/spec/lib/pickle_email_spec.rb +131 -0
  58. data/spec/lib/pickle_parser_matchers_spec.rb +70 -0
  59. data/spec/lib/pickle_parser_spec.rb +154 -0
  60. data/spec/lib/pickle_path_spec.rb +92 -0
  61. data/spec/lib/pickle_session_spec.rb +384 -0
  62. data/spec/lib/pickle_spec.rb +24 -0
  63. data/spec/spec_helper.rb +38 -0
  64. metadata +126 -0
@@ -0,0 +1,157 @@
1
+ module Pickle
2
+ module Session
3
+ class << self
4
+ def included(world_class)
5
+ proxy_to_pickle_parser(world_class)
6
+ end
7
+
8
+ def extended(world_object)
9
+ proxy_to_pickle_parser(class << world_object; self; end) # metaclass is not 2.1 compatible
10
+ end
11
+
12
+ protected
13
+ def proxy_to_pickle_parser(world_class)
14
+ world_class.class_eval do
15
+ unless methods.include?('method_missing_with_pickle_parser')
16
+ alias_method_chain :method_missing, :pickle_parser
17
+ alias_method_chain :respond_to?, :pickle_parser
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def create_model(a_model_name, fields = nil)
24
+ factory, label = *parse_model(a_model_name)
25
+ raise ArgumentError, "Can't create with an ordinal (e.g. 1st user)" if label.is_a?(Integer)
26
+ fields = fields.is_a?(Hash) ? parse_hash(fields) : parse_fields(fields)
27
+ record = pickle_config.factories[factory].create(fields)
28
+ store_model(factory, label, record)
29
+ end
30
+
31
+ def find_model(a_model_name, fields = nil)
32
+ factory, name = *parse_model(a_model_name)
33
+ raise ArgumentError, "Can't find a model with an ordinal (e.g. 1st user)" if name.is_a?(Integer)
34
+ model_class = pickle_config.factories[factory].klass
35
+ fields = fields.is_a?(Hash) ? parse_hash(fields) : parse_fields(fields)
36
+ if record = model_class.find(:first, :conditions => convert_models_to_attributes(model_class, fields))
37
+ store_model(factory, name, record)
38
+ end
39
+ end
40
+
41
+ def find_model!(a_model_name, fields = nil)
42
+ find_model(a_model_name, fields) or raise "Can't find pickle model: '#{name}' in this scenario"
43
+ end
44
+
45
+ def find_models(factory, fields = nil)
46
+ models_by_index(factory).clear
47
+ model_class = pickle_config.factories[factory].klass
48
+ records = model_class.find(:all, :conditions => convert_models_to_attributes(model_class, parse_fields(fields)))
49
+ records.each {|record| store_model(factory, nil, record)}
50
+ end
51
+
52
+ # return the original model stored by create_model or find_model
53
+ def created_model(name)
54
+ factory, name_or_index = *parse_model(name)
55
+
56
+ if name_or_index.blank?
57
+ models_by_index(factory).last
58
+ elsif name_or_index.is_a?(Integer)
59
+ models_by_index(factory)[name_or_index]
60
+ else
61
+ models_by_name(factory)[name_or_index] or raise "Can't find pickle model: '#{name}' in this scenario"
62
+ end
63
+ end
64
+
65
+ # predicate version which raises no errors
66
+ def created_model?(name)
67
+ (created_model(name) rescue nil) ? true : false
68
+ end
69
+
70
+ # return a newly selected model
71
+ def model(name)
72
+ (model = created_model(name)) && model.class.find(model.id)
73
+ end
74
+
75
+ # predicate version which raises no errors
76
+ def model?(name)
77
+ (model(name) rescue nil) ? true : false
78
+ end
79
+
80
+ # like model, but raise an error if it can't be found
81
+ def model!(name)
82
+ model(name) or raise "Can't find pickle model: '#{name}' in this scenario"
83
+ end
84
+
85
+ # like created_model, but raise an error if it can't be found
86
+ def created_model!(name)
87
+ created_model(name) or raise "Can't find pickle model: '#{name}' in this scenario"
88
+ end
89
+
90
+ # return all original models of specified type
91
+ def created_models(factory)
92
+ models_by_index(factory)
93
+ end
94
+
95
+ # return all models of specified type (freshly selected from the database)
96
+ def models(factory)
97
+ created_models(factory).map{|model| model.class.find(model.id) }
98
+ end
99
+
100
+ def respond_to_with_pickle_parser?(method, include_private = false)
101
+ respond_to_without_pickle_parser?(method, include_private) || pickle_parser.respond_to?(method, include_private)
102
+ end
103
+
104
+ protected
105
+ def method_missing_with_pickle_parser(method, *args, &block)
106
+ if pickle_parser.respond_to?(method)
107
+ pickle_parser.send(method, *args, &block)
108
+ else
109
+ method_missing_without_pickle_parser(method, *args, &block)
110
+ end
111
+ end
112
+
113
+ def pickle_parser=(parser)
114
+ parser.session = self
115
+ @pickle_parser = parser
116
+ end
117
+
118
+ def pickle_parser
119
+ @pickle_parser or self.pickle_parser = Pickle.parser
120
+ end
121
+
122
+ def pickle_config
123
+ pickle_parser.config
124
+ end
125
+
126
+ def convert_models_to_attributes(ar_class, attrs)
127
+ attrs.each do |key, val|
128
+ if val.is_a?(ActiveRecord::Base) && ar_class.column_names.include?("#{key}_id")
129
+ attrs["#{key}_id"] = val.id
130
+ attrs["#{key}_type"] = val.class.name if ar_class.column_names.include?("#{key}_type")
131
+ attrs.delete(key)
132
+ end
133
+ end
134
+ end
135
+
136
+ def models_by_name(factory)
137
+ @models_by_name ||= {}
138
+ @models_by_name[pickle_parser.canonical(factory)] ||= {}
139
+ end
140
+
141
+ def models_by_index(factory)
142
+ @models_by_index ||= {}
143
+ @models_by_index[pickle_parser.canonical(factory)] ||= []
144
+ end
145
+
146
+ # if the factory name != the model name, store under both names
147
+ def store_model(factory, name, record)
148
+ store_record(record.class.name, name, record) unless pickle_parser.canonical(factory) == pickle_parser.canonical(record.class.name)
149
+ store_record(factory, name, record)
150
+ end
151
+
152
+ def store_record(factory, name, record)
153
+ models_by_name(factory)[name] = record
154
+ models_by_index(factory) << record
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,6 @@
1
+ module Pickle
2
+ module Version
3
+ String = File.read(File.dirname(File.dirname(__FILE__)) + '/../VERSION').strip
4
+ Major, Minor, Patch = String.split('.').map{|i| i.to_i}
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ require 'pickle'
2
+
3
+ # make cucumber world pickle aware
4
+ World(Pickle::Session)
5
+
6
+ # shortcuts to regexps for use in step definition regexps
7
+ class << self
8
+ delegate :capture_model, :capture_fields, :capture_factory, :capture_plural_factory, :capture_predicate, :to => 'Pickle.parser'
9
+ end
data/lib/pickle.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'active_support'
2
+ require 'pickle/version'
3
+ require 'pickle/adapter'
4
+ require 'pickle/config'
5
+ require 'pickle/parser'
6
+ require 'pickle/session'
7
+ require 'pickle/session/parser'
8
+
9
+ # make the parser aware of models in the session (for fields refering to models)
10
+ Pickle::Parser.send :include, Pickle::Session::Parser
11
+
12
+ module Pickle
13
+ class << self
14
+ def config
15
+ @config ||= Config.new
16
+ end
17
+
18
+ def configure(&block)
19
+ config.configure(&block)
20
+ end
21
+
22
+ def parser(options = {})
23
+ @parser ||= Parser.new({:config => config}.merge(options))
24
+ end
25
+ end
26
+ end
data/pickle.gemspec ADDED
@@ -0,0 +1,110 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{kbaum-pickle}
8
+ s.version = "0.2.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ian White"]
12
+ s.date = %q{2009-12-01}
13
+ s.description = %q{Easy model creation and reference in your cucumber features}
14
+ s.email = %q{ian.w.white@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "History.txt",
21
+ "License.txt",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "Todo.txt",
25
+ "VERSION",
26
+ "features/app/app.rb",
27
+ "features/app/blueprints.rb",
28
+ "features/app/factories.rb",
29
+ "features/app/views/notifier/email.erb",
30
+ "features/app/views/notifier/user_email.erb",
31
+ "features/email/email.feature",
32
+ "features/generator/generators.feature",
33
+ "features/path/models_page.feature",
34
+ "features/path/named_route_page.feature",
35
+ "features/pickle/create_from_active_record.feature",
36
+ "features/pickle/create_from_factory_girl.feature",
37
+ "features/pickle/create_from_machinist.feature",
38
+ "features/step_definitions/email_steps.rb",
39
+ "features/step_definitions/extra_email_steps.rb",
40
+ "features/step_definitions/fork_steps.rb",
41
+ "features/step_definitions/generator_steps.rb",
42
+ "features/step_definitions/path_steps.rb",
43
+ "features/step_definitions/pickle_steps.rb",
44
+ "features/support/email.rb",
45
+ "features/support/env.rb",
46
+ "features/support/paths.rb",
47
+ "features/support/pickle.rb",
48
+ "features/support/pickle_app.rb",
49
+ "garlic.rb",
50
+ "init.rb",
51
+ "lib/pickle.rb",
52
+ "lib/pickle/adapter.rb",
53
+ "lib/pickle/config.rb",
54
+ "lib/pickle/email.rb",
55
+ "lib/pickle/email/parser.rb",
56
+ "lib/pickle/email/world.rb",
57
+ "lib/pickle/parser.rb",
58
+ "lib/pickle/parser/matchers.rb",
59
+ "lib/pickle/path.rb",
60
+ "lib/pickle/path/world.rb",
61
+ "lib/pickle/session.rb",
62
+ "lib/pickle/session/parser.rb",
63
+ "lib/pickle/version.rb",
64
+ "lib/pickle/world.rb",
65
+ "pickle.gemspec",
66
+ "rails_generators/pickle/pickle_generator.rb",
67
+ "rails_generators/pickle/templates/email.rb",
68
+ "rails_generators/pickle/templates/email_steps.rb",
69
+ "rails_generators/pickle/templates/paths.rb",
70
+ "rails_generators/pickle/templates/pickle.rb",
71
+ "rails_generators/pickle/templates/pickle_steps.rb",
72
+ "spec/lib/pickle_adapter_spec.rb",
73
+ "spec/lib/pickle_config_spec.rb",
74
+ "spec/lib/pickle_email_parser_spec.rb",
75
+ "spec/lib/pickle_email_spec.rb",
76
+ "spec/lib/pickle_parser_matchers_spec.rb",
77
+ "spec/lib/pickle_parser_spec.rb",
78
+ "spec/lib/pickle_path_spec.rb",
79
+ "spec/lib/pickle_session_spec.rb",
80
+ "spec/lib/pickle_spec.rb",
81
+ "spec/spec_helper.rb"
82
+ ]
83
+ s.homepage = %q{http://github.com/ianwhite/pickle/tree}
84
+ s.rdoc_options = ["--charset=UTF-8"]
85
+ s.require_paths = ["lib"]
86
+ s.rubygems_version = %q{1.3.5}
87
+ s.summary = %q{Easy model creation and reference in your cucumber features}
88
+ s.test_files = [
89
+ "spec/lib/pickle_adapter_spec.rb",
90
+ "spec/lib/pickle_config_spec.rb",
91
+ "spec/lib/pickle_email_parser_spec.rb",
92
+ "spec/lib/pickle_email_spec.rb",
93
+ "spec/lib/pickle_parser_matchers_spec.rb",
94
+ "spec/lib/pickle_parser_spec.rb",
95
+ "spec/lib/pickle_path_spec.rb",
96
+ "spec/lib/pickle_session_spec.rb",
97
+ "spec/lib/pickle_spec.rb",
98
+ "spec/spec_helper.rb"
99
+ ]
100
+
101
+ if s.respond_to? :specification_version then
102
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
103
+ s.specification_version = 3
104
+
105
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
106
+ else
107
+ end
108
+ else
109
+ end
110
+ end
@@ -0,0 +1,40 @@
1
+ class PickleGenerator < Rails::Generator::Base
2
+ def initialize(args, options)
3
+ super(args, options)
4
+ @generate_email_steps = args.include?('email')
5
+ if @generate_path_steps = args.include?('path') || args.include?('paths')
6
+ File.exists?('features/support/paths.rb') or raise "features/support/paths.rb not found, is your cucumber up to date?"
7
+ end
8
+ end
9
+
10
+ def manifest
11
+ record do |m|
12
+ m.directory File.join('features/step_definitions')
13
+ m.directory File.join('features/support')
14
+
15
+ current_pickle = File.exists?('features/support/pickle.rb') ? File.read('features/support/pickle.rb') : ''
16
+ pickle_assigns = {:pickle_path => false, :pickle_email => false}
17
+
18
+ if @generate_path_steps
19
+ pickle_assigns[:pickle_path] = true
20
+ current_paths = File.read('features/support/paths.rb')
21
+ unless current_paths.include?('#{capture_model}')
22
+ if current_paths =~ /^(.*)(\n\s+else\n\s+raise "Can't find.*".*$)/m
23
+ pickle_assigns[:current_paths_header] = $1
24
+ pickle_assigns[:current_paths_footer] = $2
25
+ m.template 'paths.rb', File.join('features/support', 'paths.rb'), :assigns => pickle_assigns, :collision => :force
26
+ end
27
+ end
28
+ end
29
+
30
+ if @generate_email_steps
31
+ pickle_assigns[:pickle_email] = true
32
+ m.template 'email_steps.rb', File.join('features/step_definitions', 'email_steps.rb')
33
+ m.template 'email.rb', File.join('features/support', 'email.rb')
34
+ end
35
+
36
+ m.template 'pickle_steps.rb', File.join('features/step_definitions', 'pickle_steps.rb')
37
+ m.template 'pickle.rb', File.join('features/support', 'pickle.rb'), :assigns => pickle_assigns
38
+ end
39
+ end
40
+ 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,55 @@
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
+ emails.size.should == count.to_i
19
+ end
20
+
21
+ Then(/^(\d)+ emails? should be delivered to (.*)$/) do |count, to|
22
+ emails("to: \"#{email_for(to)}\"").size.should == count.to_i
23
+ end
24
+
25
+ Then(/^(\d)+ emails? should be delivered with #{capture_fields}$/) do |count, fields|
26
+ emails(fields).size.should == count.to_i
27
+ end
28
+
29
+ Then(/^#{capture_email} should be delivered to (.+)$/) do |email_ref, to|
30
+ email(email_ref, "to: \"#{email_for(to)}\"").should_not be_nil
31
+ end
32
+
33
+ Then(/^#{capture_email} should not be delivered to (.+)$/) do |email_ref, to|
34
+ email(email_ref, "to: \"#{email_for(to)}\"").should be_nil
35
+ end
36
+
37
+ Then(/^#{capture_email} should have #{capture_fields}$/) do |email_ref, fields|
38
+ email(email_ref, fields).should_not be_nil
39
+ end
40
+
41
+ Then(/^#{capture_email} should contain "(.*)"$/) do |email_ref, text|
42
+ email(email_ref).body.should =~ /#{text}/
43
+ end
44
+
45
+ Then(/^#{capture_email} should not contain "(.*)"$/) do |email_ref, text|
46
+ email(email_ref).body.should_not =~ /#{text}/
47
+ end
48
+
49
+ Then(/^#{capture_email} should link to (.+)$/) do |email_ref, page|
50
+ email(email_ref).body.should =~ /#{path_to(page)}/
51
+ end
52
+
53
+ Then(/^show me the emails?$/) do
54
+ save_and_open_emails
55
+ end
@@ -0,0 +1,20 @@
1
+ <%= current_paths_header %>
2
+ # added by script/generate pickle path
3
+
4
+ when /^#{capture_model}(?:'s)? page$/ # eg. the forum's page
5
+ path_to_pickle $1
6
+
7
+ when /^#{capture_model}(?:'s)? #{capture_model}(?:'s)? page$/ # eg. the forum's post's page
8
+ path_to_pickle $1, $2
9
+
10
+ when /^#{capture_model}(?:'s)? #{capture_model}'s (.+?) page$/ # eg. the forum's post's comments page
11
+ path_to_pickle $1, $2, :extra => $3 # or the forum's post's edit page
12
+
13
+ when /^#{capture_model}(?:'s)? (.+?) page$/ # eg. the forum's posts page
14
+ path_to_pickle $1, :extra => $2 # or the forum's edit page
15
+
16
+ when /^the (.+?) page$/ # translate to named route
17
+ send "#{$1.downcase.gsub(' ','_')}_path"
18
+
19
+ # end added by pickle path
20
+ <%= current_paths_footer %>
@@ -0,0 +1,28 @@
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
+ # Before { Sham.reset } # to reset Sham's seed between scenarios so each run has same random sequences
10
+ #
11
+ # For FactoryGirl add: features/support/factory_girl.rb
12
+ #
13
+ # require 'factory_girl'
14
+ # require File.dirname(__FILE__) + '/../../spec/factories' # or wherever your factories are
15
+ #
16
+ # You may also need to add gem dependencies on your factory of choice in <tt>config/environments/cucumber.rb</tt>
17
+
18
+ require 'pickle/world'
19
+ # Example of configuring pickle:
20
+ #
21
+ # Pickle.configure do |config|
22
+ # config.adapters = [:machinist]
23
+ # config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"'
24
+ # end
25
+ <%- if pickle_path -%>require 'pickle/path/world'
26
+ <%- end -%>
27
+ <%- if pickle_email -%>require 'pickle/email/world'
28
+ <%- end -%>
@@ -0,0 +1,73 @@
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
+ count.to_i.times { create_model(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
+ name = plural_factory.singularize
16
+ table.hashes.each { |hash| create_model(name, hash) }
17
+ end
18
+
19
+ # find a model
20
+ Then(/^#{capture_model} should exist(?: with #{capture_fields})?$/) do |name, fields|
21
+ find_model!(name, fields)
22
+ end
23
+
24
+ # not find a model
25
+ Then(/^#{capture_model} should not exist(?: with #{capture_fields})?$/) do |name, fields|
26
+ find_model(name, fields).should be_nil
27
+ end
28
+
29
+ # find models with a table
30
+ Then(/^the following #{capture_plural_factory} should exists?:?$/) do |plural_factory, table|
31
+ name = plural_factory.singularize
32
+ table.hashes.each { |hash| find_model!(name, hash)}
33
+ end
34
+
35
+ # find exactly n models
36
+ Then(/^(\d+) #{capture_plural_factory} should exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
37
+ find_models(plural_factory.singularize, fields).size.should == count.to_i
38
+ end
39
+
40
+ # assert equality of models
41
+ Then(/^#{capture_model} should be #{capture_model}$/) do |a, b|
42
+ model!(a).should == model!(b)
43
+ end
44
+
45
+ # assert model is in another model's has_many assoc
46
+ Then(/^#{capture_model} should be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
47
+ model!(owner).send(association).should include(model!(target))
48
+ end
49
+
50
+ # assert model is not in another model's has_many assoc
51
+ Then(/^#{capture_model} should not be (?:in|one of|amongst) #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
52
+ model!(owner).send(association).should_not include(model!(target))
53
+ end
54
+
55
+ # assert model is another model's has_one/belongs_to assoc
56
+ Then(/^#{capture_model} should be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
57
+ model!(owner).send(association).should == model!(target)
58
+ end
59
+
60
+ # assert model is not another model's has_one/belongs_to assoc
61
+ Then(/^#{capture_model} should not be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
62
+ model!(owner).send(association).should_not == model!(target)
63
+ end
64
+
65
+ # assert model.predicate?
66
+ Then(/^#{capture_model} should (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
67
+ model!(name).should send("be_#{predicate.gsub(' ', '_')}")
68
+ end
69
+
70
+ # assert not model.predicate?
71
+ Then(/^#{capture_model} should not (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
72
+ model!(name).should_not send("be_#{predicate.gsub(' ', '_')}")
73
+ end