pickle 0.1.23 → 0.2.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.
@@ -1,3 +1,35 @@
1
+ == 0.2.0 - 24 Nov 2009
2
+
3
+ * 4 major improvements
4
+ * Added support for finding models using tables
5
+ Example:
6
+ Then the following users should exist:
7
+ | name |
8
+ | Fred |
9
+ | Ethel |
10
+ And the 1st user should be male
11
+ And the 2nd user should be female
12
+
13
+ * tables now support pickle refs in cells (see features/pickle/create_from_factory_girl.rb#37)
14
+
15
+ * features/support/email.rb adds an email helper for mapping names to email addresses (similar to NavigationHelper in paths.rb)
16
+
17
+ * Added ability for path_to_pickle to handle arbitrary segments
18
+ Example:
19
+ path_to_pickle('account', 'the enquiry') => account_enquiry_path(<enquiry>)
20
+
21
+ * 2 minor improvements
22
+ * fail faster in pickle steps when a pickle ref can't be found, by using model! in most places
23
+
24
+ * generated pickle steps are less picky about possessives so that pickle mappings accepted in more places
25
+ e.g. when you have
26
+ config.map 'my', 'I', 'myself', :to => 'user: "me"'
27
+ you can now do
28
+ Given I exist
29
+ ...
30
+ Then the project should be one of my assigned projects
31
+
32
+
1
33
  == 0.1.23 - 22 Nov 2009
2
34
 
3
35
  * 1 major improvement
data/Todo.txt CHANGED
@@ -1,4 +1,3 @@
1
- * Add email_for (same concept as path_to)
1
+ * cleanup path_to_pickle and paths.rb (maybe have poly_pickle_path with same semantics as polymorphic_path, but accepting pickle refs)
2
2
  * fix problem with save_and_open_emails
3
3
  * Translations
4
- * Investigate using Treetop for pre-parsing
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.23
1
+ 0.2.0
@@ -1,13 +1,9 @@
1
+ @gen
1
2
  Feature: allow pickle to generate steps
2
3
  In order to get going with pickle
3
4
  As a dev
4
5
  I want to be able to generate steps
5
6
 
6
- # Do we care anymore?
7
- # Scenario: cucumber is not yet installed
8
- # When I run "script/generate pickle"
9
- # Then I should see "try running script/generate cucumber"
10
-
11
7
  Scenario: script/generate pickle on fresh cuke install
12
8
  Given cucumber has been freshly generated
13
9
  When I run "script/generate pickle"
@@ -32,6 +28,7 @@ Feature: allow pickle to generate steps
32
28
  And the file features/support/pickle.rb should match /require 'pickle\/email\/world'/
33
29
  And the file features/step_definitions/pickle_steps.rb should be identical to the local step_definitions/pickle_steps.rb
34
30
  And the file features/step_definitions/email_steps.rb should be identical to the local step_definitions/email_steps.rb
31
+ And the file features/support/email.rb should be identical to the local support/email.rb
35
32
 
36
33
  Scenario: script/generate pickle path email on fresh cuke install
37
34
  Given cucumber has been freshly generated
@@ -44,6 +41,7 @@ Feature: allow pickle to generate steps
44
41
  And the file features/step_definitions/pickle_steps.rb should be identical to the local step_definitions/pickle_steps.rb
45
42
  And the file features/support/paths.rb should be identical to the local support/paths.rb
46
43
  And the file features/step_definitions/email_steps.rb should be identical to the local step_definitions/email_steps.rb
44
+ And the file features/support/email.rb should be identical to the local support/email.rb
47
45
 
48
46
  Scenario: regenerating pickle
49
47
  Given cucumber has been freshly generated
@@ -58,3 +56,4 @@ Feature: allow pickle to generate steps
58
56
  But the file features/support/pickle.rb should not match /require 'pickle\/world'.*require 'pickle\/world'/
59
57
  And the file features/support/pickle.rb should not match /require 'pickle\/path\/world'.*require 'pickle\/path\/world'/
60
58
  And the file features/support/pickle.rb should not match /require 'pickle\/email\/world'.*require 'pickle\/email\/world'/
59
+ And the file features/support/email.rb should be identical to the local support/email.rb
@@ -24,4 +24,20 @@ Feature: I can easily create models from my blueprints
24
24
  And another user exists with name: "Ethel", attitude_score: -1.46
25
25
  Then 2 users should exist
26
26
  And the 1st user should be a positive person
27
- And the 2nd user should not be a positive person
27
+ And the 2nd user should not be a positive person
28
+
29
+ Scenario: create and find using tables
30
+ Given the following users exist:
31
+ | name | status |
32
+ | Jim | married |
33
+ | Ethel | in a relationship with x |
34
+ Then the following users should exist:
35
+ | name |
36
+ | Jim |
37
+ | Ethel |
38
+ And the following users should exist:
39
+ | status |
40
+ | married |
41
+ | in a relationship with x |
42
+ And the 1st user should be the 3rd user
43
+ And the 2nd user should be the last user
@@ -39,8 +39,15 @@ Feature: I can easily create models from my factories
39
39
  And a tine exists with fork: the fork
40
40
 
41
41
  Then a tine should exist with fork: the fork
42
-
43
- And the fork should be the tine's fork
42
+
43
+ Scenario: create a tine with fork refs in a table
44
+ Given 2 forks exist
45
+ And the following tines exist:
46
+ | fork |
47
+ | the 1st fork |
48
+ | the 2nd fork |
49
+ Then the 1st tine should be in the 1st fork's tines
50
+ And the 2nd tine should be in the 2nd fork's tines
44
51
 
45
52
  Scenario: I create fork via a mapping
46
53
  Given killah fork exists
@@ -1,4 +1,6 @@
1
1
  # this file generated by script/generate pickle email
2
+ #
3
+ # add email mappings in features/support/email.rb
2
4
 
3
5
  ActionMailer::Base.delivery_method = :test
4
6
  ActionMailer::Base.perform_deliveries = true
@@ -7,6 +9,7 @@ Before do
7
9
  ActionMailer::Base.deliveries.clear
8
10
  end
9
11
 
12
+ # Clear the deliveries array, useful if your background sends email that you want to ignore
10
13
  Given(/^all emails? (?:have|has) been delivered$/) do
11
14
  ActionMailer::Base.deliveries.clear
12
15
  end
@@ -16,8 +19,7 @@ Given(/^(\d)+ emails? should be delivered$/) do |count|
16
19
  end
17
20
 
18
21
  Then(/^(\d)+ emails? should be delivered to (.*)$/) do |count, to|
19
- to =~ /^#{capture_model}$/ && to = model($1).email
20
- emails("to: \"#{to}\"").size.should == count.to_i
22
+ emails("to: \"#{email_for(to)}\"").size.should == count.to_i
21
23
  end
22
24
 
23
25
  Then(/^(\d)+ emails? should be delivered with #{capture_fields}$/) do |count, fields|
@@ -25,8 +27,7 @@ Then(/^(\d)+ emails? should be delivered with #{capture_fields}$/) do |count, fi
25
27
  end
26
28
 
27
29
  Then(/^#{capture_email} should be delivered to (.+)$/) do |email_ref, to|
28
- to =~ /^#{capture_model}$/ && to = model($1).email
29
- email(email_ref, "to: \"#{to}\"").should_not be_nil
30
+ email(email_ref, "to: \"#{email_for(to)}\"").should_not be_nil
30
31
  end
31
32
 
32
33
  Then(/^#{capture_email} should have #{capture_fields}$/) do |email_ref, fields|
@@ -1,8 +1,8 @@
1
- Before do
1
+ Before('@gen') do
2
2
  `mv #{Rails.root}/features/ #{Rails.root}/features.orig/ > /dev/null 2>&1`
3
3
  end
4
4
 
5
- After do
5
+ After('@gen') do
6
6
  `rm -rf #{Rails.root}/features`
7
7
  `mv #{Rails.root}/features.orig/ #{Rails.root}/features/ > /dev/null 2>&1`
8
8
  end
@@ -11,14 +11,14 @@ Given(/^(\d+) #{capture_plural_factory} exist(?: with #{capture_fields})?$/) do
11
11
  end
12
12
 
13
13
  # create models from a table
14
- Given /^the following #{capture_plural_factory} exist$/ do |plural_factory, table|
14
+ Given(/^the following #{capture_plural_factory} exists?:?$/) do |plural_factory, table|
15
15
  name = plural_factory.singularize
16
16
  table.hashes.each { |hash| create_model(name, hash) }
17
17
  end
18
18
 
19
19
  # find a model
20
20
  Then(/^#{capture_model} should exist(?: with #{capture_fields})?$/) do |name, fields|
21
- find_model(name, fields).should_not be_nil
21
+ find_model!(name, fields)
22
22
  end
23
23
 
24
24
  # not find a model
@@ -26,37 +26,48 @@ Then(/^#{capture_model} should not exist(?: with #{capture_fields})?$/) do |name
26
26
  find_model(name, fields).should be_nil
27
27
  end
28
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
+
29
35
  # find exactly n models
30
36
  Then(/^(\d+) #{capture_plural_factory} should exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
31
37
  find_models(plural_factory.singularize, fields).size.should == count.to_i
32
38
  end
33
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
+
34
45
  # assert model is in another model's has_many assoc
35
- Then(/^#{capture_model} should be (?:in|one of|amongst) #{capture_model}'s (\w+)$/) do |target, owner, association|
36
- model(owner).send(association).should include(model(target))
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))
37
48
  end
38
49
 
39
50
  # assert model is not in another model's has_many assoc
40
- Then(/^#{capture_model} should not be (?:in|one of|amongst) #{capture_model}'s (\w+)$/) do |target, owner, association|
41
- model(owner).send(association).should_not include(model(target))
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))
42
53
  end
43
54
 
44
55
  # assert model is another model's has_one/belongs_to assoc
45
- Then(/^#{capture_model} should be #{capture_model}'s (\w+)$/) do |target, owner, association|
46
- model(owner).send(association).should == model(target)
56
+ Then(/^#{capture_model} should be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
57
+ model!(owner).send(association).should == model!(target)
47
58
  end
48
59
 
49
60
  # assert model is not another model's has_one/belongs_to assoc
50
- Then(/^#{capture_model} should not be #{capture_model}'s (\w+)$/) do |target, owner, association|
51
- model(owner).send(association).should_not == model(target)
61
+ Then(/^#{capture_model} should not be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
62
+ model!(owner).send(association).should_not == model!(target)
52
63
  end
53
64
 
54
65
  # assert model.predicate?
55
66
  Then(/^#{capture_model} should (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
56
- model(name).should send("be_#{predicate.gsub(' ', '_')}")
67
+ model!(name).should send("be_#{predicate.gsub(' ', '_')}")
57
68
  end
58
69
 
59
70
  # assert not model.predicate?
60
71
  Then(/^#{capture_model} should not (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
61
- model(name).should_not send("be_#{predicate.gsub(' ', '_')}")
72
+ model!(name).should_not send("be_#{predicate.gsub(' ', '_')}")
62
73
  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)
@@ -13,31 +13,32 @@ module Pickle
13
13
  # path_to_pickle 'the user', :extra => 'new comment' # => /users/3/comments/new
14
14
  def path_to_pickle(*pickle_names)
15
15
  options = pickle_names.extract_options!
16
- models = pickle_names.map{|m| model!(m)}
16
+ resources = pickle_names.map{|n| model(n) || n.to_sym}
17
17
  if options[:extra]
18
18
  parts = options[:extra].underscore.gsub(' ','_').split("_")
19
- find_pickle_path_using_action_segment_combinations(models, parts)
19
+ find_pickle_path_using_action_segment_combinations(resources, parts)
20
20
  else
21
- pickle_path_for_models_action_segment(models, options[:action], options[:segment])
21
+ pickle_path_for_resources_action_segment(resources, options[:action], options[:segment])
22
22
  end or raise "Could not figure out a path for #{pickle_names.inspect} #{options.inspect}"
23
23
  end
24
24
 
25
25
  protected
26
- def find_pickle_path_using_action_segment_combinations(models, parts)
26
+ def find_pickle_path_using_action_segment_combinations(resources, parts)
27
27
  path = nil
28
28
  (0..parts.length).each do |idx|
29
29
  action = parts.slice(0, idx).join('_')
30
30
  segment = parts.slice(idx, parts.length).join('_')
31
- path = pickle_path_for_models_action_segment(models, action, segment) and break
31
+ path = pickle_path_for_resources_action_segment(resources, action, segment) and break
32
32
  end
33
33
  path
34
34
  end
35
35
 
36
- def pickle_path_for_models_action_segment(models, action, segment)
36
+ def pickle_path_for_resources_action_segment(resources, action, segment)
37
37
  action.blank? or action = action.downcase.gsub(' ','_')
38
38
  segment.blank? or segment = segment.downcase.gsub(' ','_')
39
- model_names = models.map{|m| m.class.name.underscore}.join("_")
40
- parts = [action, model_names, segment].reject(&:blank?)
39
+ resource_names = resources.map{|s| s.is_a?(Symbol) ? s.to_s : s.class.name.underscore}.join("_")
40
+ models = resources.reject{|s| s.is_a?(Symbol)}
41
+ parts = [action, resource_names, segment].reject(&:blank?)
41
42
  send("#{parts.join('_')}_path", *models) rescue nil
42
43
  end
43
44
  end
@@ -23,7 +23,7 @@ module Pickle
23
23
  def create_model(a_model_name, fields = nil)
24
24
  factory, label = *parse_model(a_model_name)
25
25
  raise ArgumentError, "Can't create with an ordinal (e.g. 1st user)" if label.is_a?(Integer)
26
- fields = fields.instance_of?(Hash) ? fields.dup : parse_fields(fields)
26
+ fields = fields.is_a?(Hash) ? parse_hash(fields) : parse_fields(fields)
27
27
  record = pickle_config.factories[factory].create(fields)
28
28
  store_model(factory, label, record)
29
29
  end
@@ -32,11 +32,16 @@ module Pickle
32
32
  factory, name = *parse_model(a_model_name)
33
33
  raise ArgumentError, "Can't find a model with an ordinal (e.g. 1st user)" if name.is_a?(Integer)
34
34
  model_class = pickle_config.factories[factory].klass
35
- if record = model_class.find(:first, :conditions => convert_models_to_attributes(model_class, parse_fields(fields)))
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))
36
37
  store_model(factory, name, record)
37
38
  end
38
39
  end
39
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
+
40
45
  def find_models(factory, fields = nil)
41
46
  models_by_index(factory).clear
42
47
  model_class = pickle_config.factories[factory].klass
@@ -53,7 +58,7 @@ module Pickle
53
58
  elsif name_or_index.is_a?(Integer)
54
59
  models_by_index(factory)[name_or_index]
55
60
  else
56
- models_by_name(factory)[name_or_index] or raise "model: #{name} does not refer to known model in this scenario"
61
+ models_by_name(factory)[name_or_index] or raise "Can't find pickle model: '#{name}' in this scenario"
57
62
  end
58
63
  end
59
64
 
@@ -19,6 +19,16 @@ module Pickle
19
19
  parse_field_without_model(field)
20
20
  end
21
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
22
32
  end
23
33
  end
24
34
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pickle}
8
- s.version = "0.1.23"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ian White"]
12
- s.date = %q{2009-11-22}
12
+ s.date = %q{2009-11-24}
13
13
  s.description = %q{Easy model creation and reference in your cucumber features}
14
14
  s.email = %q{ian.w.white@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -41,6 +41,7 @@ Gem::Specification.new do |s|
41
41
  "features/step_definitions/generator_steps.rb",
42
42
  "features/step_definitions/path_steps.rb",
43
43
  "features/step_definitions/pickle_steps.rb",
44
+ "features/support/email.rb",
44
45
  "features/support/env.rb",
45
46
  "features/support/paths.rb",
46
47
  "features/support/pickle.rb",
@@ -63,6 +64,7 @@ Gem::Specification.new do |s|
63
64
  "lib/pickle/world.rb",
64
65
  "pickle.gemspec",
65
66
  "rails_generators/pickle/pickle_generator.rb",
67
+ "rails_generators/pickle/templates/email.rb",
66
68
  "rails_generators/pickle/templates/email_steps.rb",
67
69
  "rails_generators/pickle/templates/paths.rb",
68
70
  "rails_generators/pickle/templates/pickle.rb",
@@ -30,6 +30,7 @@ class PickleGenerator < Rails::Generator::Base
30
30
  if @generate_email_steps
31
31
  pickle_assigns[:pickle_email] = true
32
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')
33
34
  end
34
35
 
35
36
  m.template 'pickle_steps.rb', File.join('features/step_definitions', 'pickle_steps.rb')
@@ -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)
@@ -1,4 +1,6 @@
1
1
  # this file generated by script/generate pickle email
2
+ #
3
+ # add email mappings in features/support/email.rb
2
4
 
3
5
  ActionMailer::Base.delivery_method = :test
4
6
  ActionMailer::Base.perform_deliveries = true
@@ -7,6 +9,7 @@ Before do
7
9
  ActionMailer::Base.deliveries.clear
8
10
  end
9
11
 
12
+ # Clear the deliveries array, useful if your background sends email that you want to ignore
10
13
  Given(/^all emails? (?:have|has) been delivered$/) do
11
14
  ActionMailer::Base.deliveries.clear
12
15
  end
@@ -16,8 +19,7 @@ Given(/^(\d)+ emails? should be delivered$/) do |count|
16
19
  end
17
20
 
18
21
  Then(/^(\d)+ emails? should be delivered to (.*)$/) do |count, to|
19
- to =~ /^#{capture_model}$/ && to = model($1).email
20
- emails("to: \"#{to}\"").size.should == count.to_i
22
+ emails("to: \"#{email_for(to)}\"").size.should == count.to_i
21
23
  end
22
24
 
23
25
  Then(/^(\d)+ emails? should be delivered with #{capture_fields}$/) do |count, fields|
@@ -25,8 +27,7 @@ Then(/^(\d)+ emails? should be delivered with #{capture_fields}$/) do |count, fi
25
27
  end
26
28
 
27
29
  Then(/^#{capture_email} should be delivered to (.+)$/) do |email_ref, to|
28
- to =~ /^#{capture_model}$/ && to = model($1).email
29
- email(email_ref, "to: \"#{to}\"").should_not be_nil
30
+ email(email_ref, "to: \"#{email_for(to)}\"").should_not be_nil
30
31
  end
31
32
 
32
33
  Then(/^#{capture_email} should have #{capture_fields}$/) do |email_ref, fields|
@@ -11,14 +11,14 @@ Given(/^(\d+) #{capture_plural_factory} exist(?: with #{capture_fields})?$/) do
11
11
  end
12
12
 
13
13
  # create models from a table
14
- Given /^the following #{capture_plural_factory} exist$/ do |plural_factory, table|
14
+ Given(/^the following #{capture_plural_factory} exists?:?$/) do |plural_factory, table|
15
15
  name = plural_factory.singularize
16
16
  table.hashes.each { |hash| create_model(name, hash) }
17
17
  end
18
18
 
19
19
  # find a model
20
20
  Then(/^#{capture_model} should exist(?: with #{capture_fields})?$/) do |name, fields|
21
- find_model(name, fields).should_not be_nil
21
+ find_model!(name, fields)
22
22
  end
23
23
 
24
24
  # not find a model
@@ -26,37 +26,48 @@ Then(/^#{capture_model} should not exist(?: with #{capture_fields})?$/) do |name
26
26
  find_model(name, fields).should be_nil
27
27
  end
28
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
+
29
35
  # find exactly n models
30
36
  Then(/^(\d+) #{capture_plural_factory} should exist(?: with #{capture_fields})?$/) do |count, plural_factory, fields|
31
37
  find_models(plural_factory.singularize, fields).size.should == count.to_i
32
38
  end
33
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
+
34
45
  # assert model is in another model's has_many assoc
35
- Then(/^#{capture_model} should be (?:in|one of|amongst) #{capture_model}'s (\w+)$/) do |target, owner, association|
36
- model(owner).send(association).should include(model(target))
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))
37
48
  end
38
49
 
39
50
  # assert model is not in another model's has_many assoc
40
- Then(/^#{capture_model} should not be (?:in|one of|amongst) #{capture_model}'s (\w+)$/) do |target, owner, association|
41
- model(owner).send(association).should_not include(model(target))
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))
42
53
  end
43
54
 
44
55
  # assert model is another model's has_one/belongs_to assoc
45
- Then(/^#{capture_model} should be #{capture_model}'s (\w+)$/) do |target, owner, association|
46
- model(owner).send(association).should == model(target)
56
+ Then(/^#{capture_model} should be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
57
+ model!(owner).send(association).should == model!(target)
47
58
  end
48
59
 
49
60
  # assert model is not another model's has_one/belongs_to assoc
50
- Then(/^#{capture_model} should not be #{capture_model}'s (\w+)$/) do |target, owner, association|
51
- model(owner).send(association).should_not == model(target)
61
+ Then(/^#{capture_model} should not be #{capture_model}(?:'s)? (\w+)$/) do |target, owner, association|
62
+ model!(owner).send(association).should_not == model!(target)
52
63
  end
53
64
 
54
65
  # assert model.predicate?
55
66
  Then(/^#{capture_model} should (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
56
- model(name).should send("be_#{predicate.gsub(' ', '_')}")
67
+ model!(name).should send("be_#{predicate.gsub(' ', '_')}")
57
68
  end
58
69
 
59
70
  # assert not model.predicate?
60
71
  Then(/^#{capture_model} should not (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
61
- model(name).should_not send("be_#{predicate.gsub(' ', '_')}")
72
+ model!(name).should_not send("be_#{predicate.gsub(' ', '_')}")
62
73
  end
@@ -5,72 +5,87 @@ describe Pickle::Path do
5
5
 
6
6
  describe "#path_to_pickle, when the model doesn't exist" do
7
7
  before do
8
- stub!(:model!).and_raise("foo")
8
+ stub!(:model).and_return(nil)
9
9
  end
10
10
  it "('that user', :extra => 'new comment') should raise the error raised by model!" do
11
- lambda { path_to_pickle "that user", "new comment" }.should raise_error("foo")
11
+ lambda { path_to_pickle "that user", "new comment" }.should raise_error(RuntimeError, 'Could not figure out a path for ["that user", "new comment"] {}')
12
12
  end
13
13
 
14
14
  end
15
15
 
16
16
  describe "#path_to_pickle" do
17
- before do
18
- stub!(:model!).and_return(@user = mock_model(User))
19
- end
20
- it "('a user', 'the user: \"fred\"') should retrieve 'a user', and 'the user: \"fred\"' models" do
21
- should_receive(:model!).with('a user')
22
- should_receive(:model!).with('the user: "fred"')
23
- stub!(:user_user_path).and_return('the path')
24
- path_to_pickle 'a user', 'the user: "fred"'
25
- end
17
+ describe "when model returns a user" do
18
+ before do
19
+ stub!(:model).and_return(@user = mock_model(User))
20
+ end
26
21
 
27
- it "('a user', :action => 'foo') should return foo_user_path(<user>)" do
28
- should_receive(:foo_user_path).with(@user).and_return('the path')
29
- path_to_pickle('a user', :action => 'foo').should == 'the path'
30
- end
22
+ it "('a user', 'the user: \"fred\"') should retrieve 'a user', and 'the user: \"fred\"' models" do
23
+ should_receive(:model).with('a user')
24
+ should_receive(:model).with('the user: "fred"')
25
+ stub!(:user_user_path).and_return('the path')
26
+ path_to_pickle('a user', 'the user: "fred"').should == 'the path'
27
+ end
31
28
 
32
- it "('a user', :action => 'foo') should raise informative error if foo_user_path not defined" do
33
- should_receive(:foo_user_path).with(@user).and_raise(NoMethodError)
34
- lambda { path_to_pickle('a user', :action => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
35
- end
29
+ it "('a user', :action => 'foo') should return foo_user_path(<user>)" do
30
+ should_receive(:foo_user_path).with(@user).and_return('the path')
31
+ path_to_pickle('a user', :action => 'foo').should == 'the path'
32
+ end
36
33
 
37
- it "('a user', :segment => 'foo') should return user_foo_path(<user>)" do
38
- should_receive(:user_foo_path).with(@user).and_return('the path')
39
- path_to_pickle('a user', :segment => 'foo').should == 'the path'
40
- end
34
+ it "('a user', :action => 'foo') should raise informative error if foo_user_path not defined" do
35
+ should_receive(:foo_user_path).with(@user).and_raise(NoMethodError)
36
+ lambda { path_to_pickle('a user', :action => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
37
+ end
41
38
 
42
- it "('a user', :segment => 'foo') should raise informative error if foo_user_path not defined" do
43
- should_receive(:user_foo_path).with(@user).and_raise(NoMethodError)
44
- lambda { path_to_pickle('a user', :segment => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
45
- end
39
+ it "('a user', :segment => 'foo') should return user_foo_path(<user>)" do
40
+ should_receive(:user_foo_path).with(@user).and_return('the path')
41
+ path_to_pickle('a user', :segment => 'foo').should == 'the path'
42
+ end
46
43
 
47
- it "('a user', :action => 'new', :segment => 'comment') should return new_user_comment_path(<user>)" do
48
- should_receive(:new_user_comment_path).with(@user).and_return('the path')
49
- path_to_pickle('a user', :segment => 'comment', :action => 'new').should == 'the path'
50
- end
44
+ it "('a user', :segment => 'foo') should raise informative error if foo_user_path not defined" do
45
+ should_receive(:user_foo_path).with(@user).and_raise(NoMethodError)
46
+ lambda { path_to_pickle('a user', :segment => 'foo') }.should raise_error(Exception, /Could not figure out a path for/)
47
+ end
51
48
 
52
- it "('a user', :action => 'new', :segment => 'comment') should raise informative error if new_user_comment_path not defined" do
53
- should_receive(:new_user_comment_path).with(@user).and_raise(NoMethodError)
54
- lambda { path_to_pickle('a user', :action => 'new', :segment => 'comment') }.should raise_error(Exception, /Could not figure out a path for/)
55
- end
49
+ it "('a user', :action => 'new', :segment => 'comment') should return new_user_comment_path(<user>)" do
50
+ should_receive(:new_user_comment_path).with(@user).and_return('the path')
51
+ path_to_pickle('a user', :segment => 'comment', :action => 'new').should == 'the path'
52
+ end
56
53
 
57
- it "('a user', :extra => 'new comment') should return new_user_comment_path(<user>)" do
58
- should_receive(:new_user_comment_path).with(@user).and_return('the path')
59
- path_to_pickle('a user', :extra => 'new comment').should == 'the path'
60
- end
54
+ it "('a user', :action => 'new', :segment => 'comment') should raise informative error if new_user_comment_path not defined" do
55
+ should_receive(:new_user_comment_path).with(@user).and_raise(NoMethodError)
56
+ lambda { path_to_pickle('a user', :action => 'new', :segment => 'comment') }.should raise_error(Exception, /Could not figure out a path for/)
57
+ end
61
58
 
62
- it "('a user', :extra => 'new comment') should raise informative error if new_user_comment_path not defined" do
63
- should_receive(:new_user_comment_path).with(@user).and_raise(NoMethodError)
64
- lambda { path_to_pickle('a user', :extra => 'new comment') }.should raise_error(Exception, /Could not figure out a path for/)
59
+ it "('a user', :extra => 'new comment') should return new_user_comment_path(<user>)" do
60
+ should_receive(:new_user_comment_path).with(@user).and_return('the path')
61
+ path_to_pickle('a user', :extra => 'new comment').should == 'the path'
62
+ end
63
+
64
+ it "('a user', :extra => 'new comment') should raise informative error if new_user_comment_path not defined" do
65
+ should_receive(:new_user_comment_path).with(@user).and_raise(NoMethodError)
66
+ lambda { path_to_pickle('a user', :extra => 'new comment') }.should raise_error(Exception, /Could not figure out a path for/)
67
+ end
68
+
69
+ describe "(private API)" do
70
+ it "('a user', :extra => 'new ish comment') should try combinations of 'new', 'ish', 'comment'" do
71
+ should_receive(:pickle_path_for_resources_action_segment).with([@user], '', 'new_ish_comment').once
72
+ should_receive(:pickle_path_for_resources_action_segment).with([@user], 'new', 'ish_comment').once
73
+ should_receive(:pickle_path_for_resources_action_segment).with([@user], 'new_ish', 'comment').once
74
+ should_receive(:pickle_path_for_resources_action_segment).with([@user], 'new_ish_comment', '').once
75
+ lambda { path_to_pickle('a user', :extra => 'new ish comment') }.should raise_error(Exception, /Could not figure out a path for/)
76
+ end
77
+ end
65
78
  end
66
79
 
67
- describe "(private API)" do
68
- it "('a user', :extra => 'new ish comment') should try combinations of 'new', 'ish', 'comment'" do
69
- should_receive(:pickle_path_for_models_action_segment).with([@user], '', 'new_ish_comment').once
70
- should_receive(:pickle_path_for_models_action_segment).with([@user], 'new', 'ish_comment').once
71
- should_receive(:pickle_path_for_models_action_segment).with([@user], 'new_ish', 'comment').once
72
- should_receive(:pickle_path_for_models_action_segment).with([@user], 'new_ish_comment', '').once
73
- lambda { path_to_pickle('a user', :extra => 'new ish comment') }.should raise_error(Exception, /Could not figure out a path for/)
80
+ describe "when args is a list of pickle and non pickle models" do
81
+ before do
82
+ stub!(:model).with("account").and_return(nil)
83
+ stub!(:model).with("the user").and_return(@user = mock_model(User))
84
+ end
85
+
86
+ it "('account', 'the user') should return account_user_path(<user>)" do
87
+ should_receive(:account_user_path).with(@user).and_return("the path")
88
+ path_to_pickle('account', 'the user').should == 'the path'
74
89
  end
75
90
  end
76
91
  end
@@ -188,6 +188,35 @@ describe Pickle::Session do
188
188
 
189
189
  it_should_behave_like "after storing a single user"
190
190
  end
191
+
192
+ describe "with hash" do
193
+ def do_create_model
194
+ find_model('a user', {'foo' => 'bar'})
195
+ end
196
+
197
+ it "should call User.find('user', {'foo' => 'bar'})" do
198
+ User.should_receive(:find).with(:first, :conditions => {'foo' => 'bar'}).and_return(@user)
199
+ do_create_model
200
+ end
201
+
202
+ describe "after find," do
203
+ before { do_find_model }
204
+
205
+ it_should_behave_like "after storing a single user"
206
+ end
207
+ end
208
+ end
209
+
210
+ describe "#find_model!" do
211
+ it "should call find_model" do
212
+ should_receive(:find_model).with('name', 'fields').and_return(mock('User'))
213
+ find_model!('name', 'fields')
214
+ end
215
+
216
+ it "should call raise error if find_model returns nil" do
217
+ should_receive(:find_model).with('name', 'fields').and_return(nil)
218
+ lambda { find_model!('name', 'fields') }.should raise_error
219
+ end
191
220
  end
192
221
 
193
222
  describe "#find_models" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pickle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.23
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian White
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-22 00:00:00 +00:00
12
+ date: 2009-11-24 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -47,6 +47,7 @@ files:
47
47
  - features/step_definitions/generator_steps.rb
48
48
  - features/step_definitions/path_steps.rb
49
49
  - features/step_definitions/pickle_steps.rb
50
+ - features/support/email.rb
50
51
  - features/support/env.rb
51
52
  - features/support/paths.rb
52
53
  - features/support/pickle.rb
@@ -69,6 +70,7 @@ files:
69
70
  - lib/pickle/world.rb
70
71
  - pickle.gemspec
71
72
  - rails_generators/pickle/pickle_generator.rb
73
+ - rails_generators/pickle/templates/email.rb
72
74
  - rails_generators/pickle/templates/email_steps.rb
73
75
  - rails_generators/pickle/templates/paths.rb
74
76
  - rails_generators/pickle/templates/pickle.rb