ianwhite-pickle 0.1.5 → 0.1.6
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.
- data/History.txt +38 -1
- data/Todo.txt +2 -0
- data/lib/pickle/adapter.rb +5 -2
- data/lib/pickle/config.rb +5 -8
- data/lib/pickle/email/parser.rb +18 -0
- data/lib/pickle/email/world.rb +17 -0
- data/lib/pickle/email.rb +36 -0
- data/lib/pickle/parser/matchers.rb +4 -4
- data/lib/pickle/parser.rb +3 -3
- data/lib/pickle/path/world.rb +8 -0
- data/lib/pickle/path.rb +44 -0
- data/lib/pickle/{parser/with_session.rb → session/parser.rb} +2 -2
- data/lib/pickle/session.rb +61 -32
- data/lib/pickle/version.rb +1 -1
- data/lib/pickle/world.rb +12 -0
- data/lib/pickle.rb +2 -13
- data/rails_generators/pickle/pickle_generator.rb +20 -7
- data/rails_generators/pickle/templates/env.rb +5 -3
- data/rails_generators/pickle/templates/pickle_email_steps.rb +50 -0
- data/rails_generators/pickle/templates/pickle_path_steps.rb +53 -0
- data/rails_generators/pickle/templates/pickle_steps.rb +1 -2
- data/spec/lib/pickle_adapter_spec.rb +10 -2
- data/spec/lib/pickle_config_spec.rb +4 -8
- data/spec/lib/pickle_email_parser_spec.rb +49 -0
- data/spec/lib/pickle_email_spec.rb +131 -0
- data/spec/lib/pickle_path_spec.rb +68 -0
- data/spec/lib/pickle_session_spec.rb +68 -53
- metadata +17 -6
- data/lib/pickle/injector.rb +0 -18
- data/spec/lib/pickle_injector_spec.rb +0 -22
data/History.txt
CHANGED
@@ -1,3 +1,39 @@
|
|
1
|
+
== 0.1.6
|
2
|
+
|
3
|
+
* 1 API change
|
4
|
+
* to use pickle env.rb should contain "require 'pickle/world'". You should remove all trace of
|
5
|
+
pickle from features/support/env.rb and re run script/generate pickle
|
6
|
+
|
7
|
+
* 2 major enhancements
|
8
|
+
|
9
|
+
* generate email steps with `script/generate pickle email`
|
10
|
+
email steps allow you to do things like this:
|
11
|
+
|
12
|
+
Then 2 emails should be delivered
|
13
|
+
And the first email should be delivered to fred@gmail.com
|
14
|
+
And the 2nd email should be delivered to the user: "ethel"
|
15
|
+
|
16
|
+
Then 1 email should be delivered with subject: "Activate your account"
|
17
|
+
And the email should link to the user's page
|
18
|
+
|
19
|
+
take a look at features/step_definitions/pickle_email_steps.rb
|
20
|
+
|
21
|
+
* generate path steps with `script/generate pickle path`
|
22
|
+
path steps allow you to do things like this
|
23
|
+
|
24
|
+
When I go to the comment's page
|
25
|
+
Then I should be at the user's new comment page
|
26
|
+
|
27
|
+
take a look at features/step_definitions/pickle_path_steps.rb, and modify page_to_path to suit your needs
|
28
|
+
|
29
|
+
* 4 minor enhancements
|
30
|
+
* Improved documentation
|
31
|
+
* abstract models no longer kill pickle
|
32
|
+
* Actually test that the generators work
|
33
|
+
* Made Pickle::Session a plain ole mixin, as a separate class was unnecessary
|
34
|
+
* Pickle uses the cucumber World API
|
35
|
+
|
36
|
+
|
1
37
|
== 0.1.5
|
2
38
|
|
3
39
|
* API change
|
@@ -11,11 +47,12 @@
|
|
11
47
|
* configuration can now occur any time before a step is defined, which makes
|
12
48
|
for much more intuitive env.rb
|
13
49
|
|
14
|
-
*
|
50
|
+
* 2 minor enhancement
|
15
51
|
* predicate matching is less prone to step conflicts because we preload a
|
16
52
|
big list of all the predicate and column methods
|
17
53
|
* field values now handle booleans and numerics
|
18
54
|
|
55
|
+
|
19
56
|
== 0.1.4
|
20
57
|
|
21
58
|
* 1 major enhancement
|
data/Todo.txt
CHANGED
data/lib/pickle/adapter.rb
CHANGED
@@ -23,8 +23,11 @@ module Pickle
|
|
23
23
|
self.model_classes = nil
|
24
24
|
|
25
25
|
def self.model_classes
|
26
|
-
|
27
|
-
|
26
|
+
# remove abstract and framework classes
|
27
|
+
@@model_classes ||= ::ActiveRecord::Base.send(:subclasses).reject do |klass|
|
28
|
+
klass.abstract_class? ||
|
29
|
+
(defined?(CGI::Session::ActiveRecordStore::Session) && klass == CGI::Session::ActiveRecordStore::Session) ||
|
30
|
+
(defined?(::ActiveRecord::SessionStore::Session) && klass == ::ActiveRecord::SessionStore::Session)
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
data/lib/pickle/config.rb
CHANGED
@@ -25,14 +25,10 @@ module Pickle
|
|
25
25
|
factories.merge(adapter.factories.inject({}){|h, f| h.merge(f.name => f)})
|
26
26
|
end
|
27
27
|
end
|
28
|
-
|
29
|
-
def factory_names
|
30
|
-
factories.keys
|
31
|
-
end
|
32
28
|
|
33
29
|
def predicates
|
34
|
-
@predicates ||= Pickle::Adapter.model_classes.map do |
|
35
|
-
|
30
|
+
@predicates ||= Pickle::Adapter.model_classes.map do |k|
|
31
|
+
k.public_instance_methods.select{|m| m =~ /\?$/} + k.column_names
|
36
32
|
end.flatten.uniq
|
37
33
|
end
|
38
34
|
|
@@ -44,8 +40,9 @@ module Pickle
|
|
44
40
|
def map(*args)
|
45
41
|
options = args.extract_options!
|
46
42
|
raise ArgumentError, "Usage: map 'search' [, 'search2', ...] :to => 'replace'" unless args.any? && options[:to].is_a?(String)
|
47
|
-
|
48
|
-
|
43
|
+
args.each do |search|
|
44
|
+
self.mappings << OpenStruct.new(:search => search, :replace => options[:to])
|
45
|
+
end
|
49
46
|
end
|
50
47
|
end
|
51
48
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Pickle
|
2
|
+
module Email
|
3
|
+
# add ability to parse emails
|
4
|
+
module Parser
|
5
|
+
def match_email
|
6
|
+
"(?:#{match_prefix}?(?:#{match_index} )?email)"
|
7
|
+
end
|
8
|
+
|
9
|
+
def capture_email
|
10
|
+
"(#{match_email})"
|
11
|
+
end
|
12
|
+
|
13
|
+
def capture_index_in_email
|
14
|
+
"(?:#{match_prefix}?(?:#{capture_index} )?email)"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'pickle'
|
2
|
+
require 'pickle/email'
|
3
|
+
require 'pickle/email/parser'
|
4
|
+
|
5
|
+
# add email parser expressions
|
6
|
+
Pickle::Parser.send :include, Pickle::Email::Parser
|
7
|
+
|
8
|
+
# make world pickle/email aware
|
9
|
+
World do |world|
|
10
|
+
world.extend Pickle::Email
|
11
|
+
world
|
12
|
+
end
|
13
|
+
|
14
|
+
# shortcuts for use in step regexps
|
15
|
+
class << self
|
16
|
+
delegate :capture_email, :to => 'Pickle.parser'
|
17
|
+
end
|
data/lib/pickle/email.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Pickle
|
2
|
+
module Email
|
3
|
+
# return the deliveries array, optionally selected by the passed fields
|
4
|
+
def emails(fields = nil)
|
5
|
+
@emails = ActionMailer::Base.deliveries.select {|m| email_has_fields?(m, fields)}
|
6
|
+
end
|
7
|
+
|
8
|
+
def email(ref, fields = nil)
|
9
|
+
(match = ref.match(/^#{capture_index_in_email}$/)) or raise ArgumentError, "argument should match #{match_email}"
|
10
|
+
@emails or raise RuntimeError, "Call #emails before calling #email"
|
11
|
+
index = parse_index(match[1])
|
12
|
+
email_has_fields?(@emails[index], fields) ? @emails[index] : nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def email_has_fields?(email, fields)
|
16
|
+
parse_fields(fields).each do |key, val|
|
17
|
+
return false unless (Array(email.send(key)) & Array(val)).any?
|
18
|
+
end
|
19
|
+
true
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
# Saves the emails out to RAILS_ROOT/tmp/ and opens it in the default
|
24
|
+
# web browser if on OS X. (depends on webrat)
|
25
|
+
def save_and_open_emails
|
26
|
+
emails_to_open = @emails || emails
|
27
|
+
filename = "#{RAILS_ROOT}/tmp/webrat-email-#{Time.now.to_i}.html"
|
28
|
+
File.open(filename, "w") do |f|
|
29
|
+
emails_to_open.each_with_index do |e, i|
|
30
|
+
f.write "<h1>Email #{i+1}</h1><pre>#{e}</pre><hr />"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
open_in_browser(filename)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -10,7 +10,7 @@ module Pickle
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def match_prefix
|
13
|
-
'(?:(?:
|
13
|
+
'(?:(?:a|an|another|the|that) )'
|
14
14
|
end
|
15
15
|
|
16
16
|
def match_quoted
|
@@ -34,15 +34,15 @@ module Pickle
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def match_mapping
|
37
|
-
|
37
|
+
"(?:#{config.mappings.map(&:search).join('|')})"
|
38
38
|
end
|
39
39
|
|
40
40
|
def match_factory
|
41
|
-
"(?:#{config.
|
41
|
+
"(?:#{config.factories.keys.map{|n| n.gsub('_','[_ ]')}.join('|')})"
|
42
42
|
end
|
43
43
|
|
44
44
|
def match_plural_factory
|
45
|
-
"(?:#{config.
|
45
|
+
"(?:#{config.factories.keys.map{|n| n.pluralize.gsub('_','[_ ]')}.join('|')})"
|
46
46
|
end
|
47
47
|
|
48
48
|
def match_indexed_model
|
data/lib/pickle/parser.rb
CHANGED
@@ -34,7 +34,7 @@ module Pickle
|
|
34
34
|
|
35
35
|
# returns really underscored name
|
36
36
|
def canonical(str)
|
37
|
-
str.to_s.gsub(' ','_').
|
37
|
+
str.to_s.underscore.gsub(' ','_').gsub('/','_')
|
38
38
|
end
|
39
39
|
|
40
40
|
# return [factory_name, name or integer index]
|
@@ -49,9 +49,9 @@ module Pickle
|
|
49
49
|
|
50
50
|
def parse_index(index)
|
51
51
|
case index
|
52
|
-
when '',
|
52
|
+
when nil, '', 'last' then -1
|
53
53
|
when /#{capture_number_in_ordinal}/ then $1.to_i - 1
|
54
|
-
when
|
54
|
+
when 'first' then 0
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
data/lib/pickle/path.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Pickle
|
2
|
+
module Path
|
3
|
+
# given args of pickle model name, and an optional extra action, or segment, will attempt to find
|
4
|
+
# a matching named route
|
5
|
+
#
|
6
|
+
# pickle_path 'the user', :action => 'edit' # => /users/3/edit
|
7
|
+
# pickle_path 'the user', 'the comment' # => /users/3/comments/1
|
8
|
+
# pickle_path 'the user', :segment => 'comments' # => /users/3/comments
|
9
|
+
#
|
10
|
+
# If you don;t know if the 'extra' part of the path is an action or a segment, then just
|
11
|
+
# pass it as 'extra' and this method will run through the possibilities
|
12
|
+
#
|
13
|
+
# pickle_path 'the user', :extra => 'new comment' # => /users/3/comments/new
|
14
|
+
def pickle_path(*pickle_names)
|
15
|
+
options = pickle_names.extract_options!
|
16
|
+
models = pickle_names.map{|m| model(m)}
|
17
|
+
if options[:extra]
|
18
|
+
parts = options[:extra].underscore.gsub(' ','_').split("_")
|
19
|
+
find_pickle_path_using_action_segment_combinations(models, parts)
|
20
|
+
else
|
21
|
+
pickle_path_for_models_action_segment(models, options[:action], options[:segment])
|
22
|
+
end or raise "Could not figure out a path for #{pickle_names.inspect} #{options.inspect}"
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
def find_pickle_path_using_action_segment_combinations(models, parts)
|
27
|
+
path = nil
|
28
|
+
(0..parts.length).each do |idx|
|
29
|
+
action = parts.slice(0, idx).join('_')
|
30
|
+
segment = parts.slice(idx, parts.length).join('_')
|
31
|
+
path = pickle_path_for_models_action_segment(models, action, segment) and break
|
32
|
+
end
|
33
|
+
path
|
34
|
+
end
|
35
|
+
|
36
|
+
def pickle_path_for_models_action_segment(models, action, segment)
|
37
|
+
action.blank? or action = action.downcase.gsub(' ','_')
|
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?)
|
41
|
+
send("#{parts.join('_')}_path", *models) rescue nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/pickle/session.rb
CHANGED
@@ -1,45 +1,56 @@
|
|
1
1
|
module Pickle
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
6
21
|
end
|
7
|
-
|
22
|
+
|
8
23
|
def create_model(a_model_name, fields = nil)
|
9
|
-
factory, label = *
|
24
|
+
factory, label = *parse_model(a_model_name)
|
10
25
|
raise ArgumentError, "Can't create with an ordinal (e.g. 1st user)" if label.is_a?(Integer)
|
11
|
-
record =
|
26
|
+
record = pickle_config.factories[factory].create(parse_fields(fields))
|
12
27
|
store_model(factory, label, record)
|
13
28
|
end
|
14
29
|
|
15
30
|
def find_model(a_model_name, fields = nil)
|
16
|
-
factory, name = *
|
31
|
+
factory, name = *parse_model(a_model_name)
|
17
32
|
raise ArgumentError, "Can't find a model with an ordinal (e.g. 1st user)" if name.is_a?(Integer)
|
18
|
-
model_class =
|
19
|
-
if record = model_class.find(:first, :conditions => convert_models_to_attributes(model_class,
|
33
|
+
model_class = pickle_config.factories[factory].klass
|
34
|
+
if record = model_class.find(:first, :conditions => convert_models_to_attributes(model_class, parse_fields(fields)))
|
20
35
|
store_model(factory, name, record)
|
21
36
|
end
|
22
37
|
end
|
23
38
|
|
24
39
|
def find_models(factory, fields = nil)
|
25
|
-
|
26
|
-
|
40
|
+
models_by_index(factory).clear
|
41
|
+
model_class = pickle_config.factories[factory].klass
|
42
|
+
records = model_class.find(:all, :conditions => convert_models_to_attributes(model_class, parse_fields(fields)))
|
27
43
|
records.each {|record| store_model(factory, nil, record)}
|
28
44
|
end
|
29
|
-
|
30
|
-
def clear_models(factory)
|
31
|
-
models_by_name(factory).clear
|
32
|
-
models_by_factory(factory).clear
|
33
|
-
end
|
34
45
|
|
35
46
|
# return the original model stored by create_model or find_model
|
36
47
|
def created_model(name)
|
37
|
-
factory, name_or_index = *
|
48
|
+
factory, name_or_index = *parse_model(name)
|
38
49
|
|
39
50
|
if name_or_index.blank?
|
40
|
-
|
51
|
+
models_by_index(factory).last
|
41
52
|
elsif name_or_index.is_a?(Integer)
|
42
|
-
|
53
|
+
models_by_index(factory)[name_or_index]
|
43
54
|
else
|
44
55
|
models_by_name(factory)[name_or_index] or raise "model: #{name} does not refer to known model in this scenario"
|
45
56
|
end
|
@@ -62,7 +73,7 @@ module Pickle
|
|
62
73
|
|
63
74
|
# return all original models of specified type
|
64
75
|
def created_models(factory)
|
65
|
-
|
76
|
+
models_by_index(factory)
|
66
77
|
end
|
67
78
|
|
68
79
|
# return all models of specified type (freshly selected from the database)
|
@@ -70,14 +81,32 @@ module Pickle
|
|
70
81
|
created_models(factory).map{|model| model.class.find(model.id) }
|
71
82
|
end
|
72
83
|
|
84
|
+
def respond_to_with_pickle_parser?(method, include_private = false)
|
85
|
+
respond_to_without_pickle_parser?(method, include_private) || pickle_parser.respond_to?(method, include_private)
|
86
|
+
end
|
87
|
+
|
73
88
|
protected
|
74
|
-
|
75
|
-
|
76
|
-
|
89
|
+
def method_missing_with_pickle_parser(method, *args, &block)
|
90
|
+
if pickle_parser.respond_to?(method)
|
91
|
+
pickle_parser.send(method, *args, &block)
|
92
|
+
else
|
93
|
+
method_missing_without_pickle_parser(method, *args, &block)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def pickle_parser=(parser)
|
77
98
|
parser.session = self
|
78
|
-
@
|
99
|
+
@pickle_parser = parser
|
79
100
|
end
|
80
101
|
|
102
|
+
def pickle_parser
|
103
|
+
@pickle_parser or self.pickle_parser = Pickle.parser
|
104
|
+
end
|
105
|
+
|
106
|
+
def pickle_config
|
107
|
+
pickle_parser.config
|
108
|
+
end
|
109
|
+
|
81
110
|
def convert_models_to_attributes(ar_class, attrs)
|
82
111
|
attrs.each do |key, val|
|
83
112
|
if val.is_a?(ActiveRecord::Base) && ar_class.column_names.include?("#{key}_id")
|
@@ -90,23 +119,23 @@ module Pickle
|
|
90
119
|
|
91
120
|
def models_by_name(factory)
|
92
121
|
@models_by_name ||= {}
|
93
|
-
@models_by_name[factory] ||= {}
|
122
|
+
@models_by_name[pickle_parser.canonical(factory)] ||= {}
|
94
123
|
end
|
95
124
|
|
96
|
-
def
|
97
|
-
@
|
98
|
-
@
|
125
|
+
def models_by_index(factory)
|
126
|
+
@models_by_index ||= {}
|
127
|
+
@models_by_index[pickle_parser.canonical(factory)] ||= []
|
99
128
|
end
|
100
129
|
|
101
130
|
# if the factory name != the model name, store under both names
|
102
131
|
def store_model(factory, name, record)
|
103
|
-
store_record(
|
132
|
+
store_record(record.class.name, name, record) unless pickle_parser.canonical(factory) == pickle_parser.canonical(record.class.name)
|
104
133
|
store_record(factory, name, record)
|
105
134
|
end
|
106
|
-
|
135
|
+
|
107
136
|
def store_record(factory, name, record)
|
108
137
|
models_by_name(factory)[name] = record
|
109
|
-
|
138
|
+
models_by_index(factory) << record
|
110
139
|
end
|
111
140
|
end
|
112
141
|
end
|
data/lib/pickle/version.rb
CHANGED
data/lib/pickle/world.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'pickle'
|
2
|
+
|
3
|
+
# make cucumber world pickle aware
|
4
|
+
World do |world|
|
5
|
+
world.extend Pickle::Session
|
6
|
+
world
|
7
|
+
end
|
8
|
+
|
9
|
+
# shortcuts to regexps for use in step definition regexps
|
10
|
+
class << self
|
11
|
+
delegate :capture_model, :capture_fields, :capture_factory, :capture_plural_factory, :capture_predicate, :to => 'Pickle.parser'
|
12
|
+
end
|
data/lib/pickle.rb
CHANGED
@@ -3,12 +3,11 @@ require 'pickle/version'
|
|
3
3
|
require 'pickle/adapter'
|
4
4
|
require 'pickle/config'
|
5
5
|
require 'pickle/parser'
|
6
|
-
require 'pickle/parser/with_session'
|
7
6
|
require 'pickle/session'
|
8
|
-
require 'pickle/
|
7
|
+
require 'pickle/session/parser'
|
9
8
|
|
10
9
|
# make the parser aware of models in the session (for fields refering to models)
|
11
|
-
Pickle::Parser.send :include, Pickle::Parser
|
10
|
+
Pickle::Parser.send :include, Pickle::Session::Parser
|
12
11
|
|
13
12
|
module Pickle
|
14
13
|
class << self
|
@@ -24,14 +23,4 @@ module Pickle
|
|
24
23
|
@parser ||= Parser.new({:config => config}.merge(options))
|
25
24
|
end
|
26
25
|
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# inject the pickle session into integration session if we have one (TODO: inject into merb etc?)
|
30
|
-
if defined?(ActionController::Integration::Session)
|
31
|
-
Pickle::Injector.inject Pickle::Session, :into => ActionController::Integration::Session
|
32
|
-
end
|
33
|
-
|
34
|
-
# shortcuts to regexps for use in step definitions
|
35
|
-
class << self
|
36
|
-
delegate :capture_model, :capture_fields, :capture_factory, :capture_plural_factory, :capture_predicate, :to => 'Pickle.parser'
|
37
26
|
end
|
@@ -1,19 +1,32 @@
|
|
1
1
|
class PickleGenerator < Rails::Generator::Base
|
2
|
-
def initialize(
|
3
|
-
super(
|
2
|
+
def initialize(args, options)
|
3
|
+
super(args, options)
|
4
|
+
@generate_path_steps = args.include?('page') || args.include?('path')
|
5
|
+
@generate_email_steps = args.include?('email')
|
4
6
|
File.exists?('features/support/env.rb') or raise "features/support/env.rb not found, try running script/generate cucumber"
|
5
7
|
end
|
6
8
|
|
7
9
|
def manifest
|
8
10
|
record do |m|
|
9
11
|
m.directory File.join('features/step_definitions')
|
10
|
-
|
12
|
+
|
11
13
|
current_env = File.read('features/support/env.rb')
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
env_assigns = {:current_env => current_env, :pickle => false, :pickle_path => false, :pickle_email => false}
|
15
|
+
|
16
|
+
if @generate_path_steps
|
17
|
+
env_assigns[:pickle_path] = true unless current_env.include?("require 'pickle/path/world'")
|
18
|
+
m.template 'pickle_path_steps.rb', File.join('features/step_definitions', "pickle_path_steps.rb")
|
19
|
+
end
|
20
|
+
|
21
|
+
if @generate_email_steps
|
22
|
+
env_assigns[:pickle_email] = true unless current_env.include?("require 'pickle/email/world'")
|
23
|
+
m.template 'pickle_email_steps.rb', File.join('features/step_definitions', "pickle_email_steps.rb")
|
16
24
|
end
|
25
|
+
|
26
|
+
env_assigns[:pickle] = true unless current_env.include?("require 'pickle/world'")
|
27
|
+
m.template 'pickle_steps.rb', File.join('features/step_definitions', "pickle_steps.rb")
|
28
|
+
|
29
|
+
m.template 'env.rb', File.join('features/support', "env.rb"), :assigns => env_assigns, :collision => :force
|
17
30
|
end
|
18
31
|
end
|
19
32
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
<%= current_env %>
|
2
|
-
require 'pickle'
|
3
|
-
|
2
|
+
<% if pickle %>require 'pickle/world'<% end %>
|
3
|
+
<% if pickle_path %>require 'pickle/path/world'<% end %>
|
4
|
+
<% if pickle_email %>require 'pickle/email/world'<% end %>
|
5
|
+
<% if pickle %>
|
4
6
|
# Example of configuring pickle:
|
5
7
|
#
|
6
8
|
# Pickle.configure do |config|
|
7
9
|
# config.adaptors = [:machinist]
|
8
10
|
# config.map 'I', 'myself', 'me', 'my', :to => 'user: "me"'
|
9
11
|
# end
|
10
|
-
|
12
|
+
<% end -%>
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# this file generated by script/generate pickle email
|
2
|
+
|
3
|
+
ActionMailer::Base.delivery_method = :test
|
4
|
+
ActionMailer::Base.perform_deliveries = true
|
5
|
+
|
6
|
+
Before do
|
7
|
+
ActionMailer::Base.deliveries.clear
|
8
|
+
end
|
9
|
+
|
10
|
+
Given(/^all emails? (?:have|has) been delivered$/) do
|
11
|
+
ActionMailer::Base.deliveries.clear
|
12
|
+
end
|
13
|
+
|
14
|
+
Given(/^(\d)+ emails? should be delivered$/) do |count|
|
15
|
+
emails.size.should == count.to_i
|
16
|
+
end
|
17
|
+
|
18
|
+
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
|
21
|
+
end
|
22
|
+
|
23
|
+
Then(/^(\d)+ emails? should be delivered with #{capture_fields}$/) do |count, fields|
|
24
|
+
emails(fields).size.should == count.to_i
|
25
|
+
end
|
26
|
+
|
27
|
+
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
|
+
end
|
31
|
+
|
32
|
+
Then(/^#{capture_email} should have #{capture_fields}$/) do |email_ref, fields|
|
33
|
+
email(email_ref, fields).should_not be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
Then(/^#{capture_email} should contain "(.*)"$/) do |email_ref, text|
|
37
|
+
email(email_ref).body.should =~ /#{text}/
|
38
|
+
end
|
39
|
+
|
40
|
+
Then(/^#{capture_email} should not contain "(.*)"$/) do |email_ref, text|
|
41
|
+
email(email_ref).body.should_not =~ /#{text}/
|
42
|
+
end
|
43
|
+
|
44
|
+
Then(/^#{capture_email} should link to (.+) page$/) do |email_ref, page|
|
45
|
+
email(email_ref).body.should =~ /#{page_to_path(page)}/
|
46
|
+
end
|
47
|
+
|
48
|
+
Then(/^show me the emails?$/) do
|
49
|
+
save_and_open_emails
|
50
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# this file generated by script/generate pickle page.
|
2
|
+
# You should edit the page_to_path method below for your own app's needs
|
3
|
+
|
4
|
+
# When I go to /sessions/new
|
5
|
+
When(/^I go to \/(.+?)$/) do |path|
|
6
|
+
visit "/#{path}"
|
7
|
+
end
|
8
|
+
|
9
|
+
# Then I should be at /sessions/new
|
10
|
+
Then(/^I should be at \/(.+?)$/) do |path|
|
11
|
+
request.path.should =~ /^\/#{path}/
|
12
|
+
end
|
13
|
+
|
14
|
+
# When I go to the posts's new comment page
|
15
|
+
When(/^I go to (.+?) page$/) do |page|
|
16
|
+
visit page_to_path(page)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Then I should be at the posts's new comment page
|
20
|
+
Then(/^I should be at (.+?) page$/) do |page|
|
21
|
+
request.path.should =~ /^#{page_to_path(page)}/
|
22
|
+
end
|
23
|
+
|
24
|
+
# passed a string like 'the home', returns a path
|
25
|
+
def page_to_path(page)
|
26
|
+
case page
|
27
|
+
# add your own app-specific mappings, e.g.
|
28
|
+
#
|
29
|
+
# when 'the home'
|
30
|
+
# '/'
|
31
|
+
#
|
32
|
+
# when /$#{capture_model}'s activation^/
|
33
|
+
# activation_by_code_path(created_model($1).activation_code)
|
34
|
+
|
35
|
+
when /^#{capture_model}'s$/ # the forum's
|
36
|
+
pickle_path $1
|
37
|
+
|
38
|
+
when /^#{capture_model}'s #{capture_model}'s$/ # the forum's post's
|
39
|
+
pickle_path $1, $2
|
40
|
+
|
41
|
+
when /^#{capture_model}'s #{capture_model}'s (.+?)$/ # the forum's post's comments
|
42
|
+
pickle_path $1, $2, :extra => $3
|
43
|
+
|
44
|
+
when /^#{capture_model}'s (.+?)$/ # the post's comments
|
45
|
+
pickle_path $1, :extra => $2
|
46
|
+
|
47
|
+
when /^the (.+?)$/ # the new session
|
48
|
+
send "#{$1.downcase.gsub(' ','_')}_path"
|
49
|
+
|
50
|
+
else
|
51
|
+
raise "Could not map '#{page}' page to a path"
|
52
|
+
end
|
53
|
+
end
|