pickle 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,11 @@
1
+ == 0.2.2 - 25 Feb 2010
2
+
3
+ * 3 improvements
4
+ * Added ability to follow links in emails (see email_steps.rb) [Michael Moen]
5
+ * Added a step definition for doing stuff like: Then the user's name should be "Tobi" [Tobi Knaup]
6
+ * Docfixes, mostly about testing [Nicholas Rutherford]
7
+
8
+
1
9
  == 0.2.1 - 1 Dec 2009
2
10
 
3
11
  * 2 minor improvements
data/README.rdoc CHANGED
@@ -13,7 +13,7 @@ building complex givens which require a bunch of models collaborating
13
13
 
14
14
  <b>Gemcutter</b> for the gem: http://gemcutter.org/gems/pickle
15
15
 
16
- <b>API</b> docs: http://ianwhite.github.com/pickle/doc
16
+ <b>API</b> docs: {Pickle rdoc on github}[http://ianwhite.github.com/pickle/doc/]
17
17
 
18
18
  <b>Google group</b> for questions: http://groups.google.com/group/pickle-cucumber
19
19
 
@@ -43,13 +43,29 @@ Install pickle either as a rails plugin, or a gem
43
43
 
44
44
  It's tested against all stable branches of 2.x rails, and edge, with the latest versions of rspec, cucumber, factory_girl, machinist.
45
45
 
46
+ == Run the tests
47
+
48
+ You can run the test with <b>garlic</b> http://github.com/ianwhite/garlic, which tests against different versions of rails.
49
+
50
+ Or, you can make a test rails app:
51
+
52
+ cd ~/wherever_you_work
53
+ rails pickle_test_project; cd pickle_test_project
54
+ script/generate rspec
55
+ script/generate cucumber --rspec
56
+ script/plugin install git://github.com/ianwhite/pickle.git
57
+ cd vendor/plugins/pickle
58
+ rake spec
59
+ cucumber features
60
+
46
61
  == Contributors
47
62
 
48
63
  The following people have made Pickle better:
49
64
 
50
65
  * {Nick Rutherford}[http://github.com/nruth]
51
- * Tobi Knaup
66
+ * {Tobi Knaup}[http://github.com/guenter]
52
67
  * {Michael MacDonald}[http://github.com/schlick]
68
+ * {Michael Moen}[http://github.com/UnderpantsGnome]
53
69
 
54
70
  == Get Started
55
71
 
data/Rakefile CHANGED
@@ -23,7 +23,7 @@ Spec::Rake::SpecTask.new(:rcov) do |t|
23
23
  t.spec_files = FileList['spec/**/*_spec.rb']
24
24
  t.rcov = true
25
25
  t.rcov_dir = 'doc/coverage'
26
- t.rcov_opts = ['--text-report', '--exclude', "spec/,rcov.rb,#{File.expand_path(File.join(File.dirname(__FILE__),'../../..'))}"]
26
+ t.rcov_opts = ['--text-report', '--exclude', "gems/,features/,/Library,spec/,rcov.rb,#{File.expand_path(File.join(File.dirname(__FILE__),'../../..'))}"]
27
27
  end
28
28
 
29
29
  namespace :rcov do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -36,4 +36,25 @@ Feature: I can test emails are sent
36
36
  And the user's email is delivered
37
37
  Then 1 email should be delivered to the user
38
38
  And the email should contain "Dear Fred"
39
- And the email should link to the user's page
39
+ And the email should link to the user's page
40
+
41
+ Scenario: Following the first link in an email
42
+ Given a user exists with name: "Fred", email: "fred@gmail.com"
43
+ And an email "cool" with body: "some text <a href='http://example.com/users/1'>example page</a> more text" is delivered to fred@gmail.com
44
+ Then 1 email should be delivered to the user
45
+ And I click the first link in the email
46
+ Then I should be at the user's page
47
+
48
+ Scenario: Following a link in an email by url
49
+ Given a user exists with name: "Fred", email: "fred@gmail.com"
50
+ And an email "cool" with body: "some text <a href='http://example.com/users/1'>example page</a> more text" is delivered to fred@gmail.com
51
+ Then 1 email should be delivered to the user
52
+ And I follow "example.com/" in the email
53
+ Then I should be at the user's page
54
+
55
+ Scenario: Following a link in an email by the text
56
+ Given a user exists with name: "Fred", email: "fred@gmail.com"
57
+ And an email "cool" with body: "some text <a href='http://example.com/users/1'>example page</a> more text" is delivered to fred@gmail.com
58
+ Then 1 email should be delivered to the user
59
+ And I follow "example page" in the email
60
+ Then I should be at the user's page
@@ -18,6 +18,14 @@ Given(/^(\d)+ emails? should be delivered$/) do |count|
18
18
  emails.size.should == count.to_i
19
19
  end
20
20
 
21
+ When(/^(?:I|they) follow "([^"]*?)" in #{capture_email}$/) do |link, email_ref|
22
+ visit_in_email(email(email_ref), link)
23
+ end
24
+
25
+ When(/^(?:I|they) click the first link in #{capture_email}$/) do |email_ref|
26
+ click_first_link_in_email(email(email_ref))
27
+ end
28
+
21
29
  Then(/^(\d)+ emails? should be delivered to (.*)$/) do |count, to|
22
30
  emails("to: \"#{email_for(to)}\"").size.should == count.to_i
23
31
  end
@@ -8,7 +8,7 @@ After('@gen') do
8
8
  end
9
9
 
10
10
  Given(/^cucumber has been freshly generated$/) do
11
- `cd #{Rails.root}; script/generate cucumber -f`
11
+ `cd #{Rails.root}; script/generate cucumber -f --webrat`
12
12
  end
13
13
 
14
14
  Given(/^pickle path email has been freshly generated$/) do
@@ -70,4 +70,20 @@ end
70
70
  # assert not model.predicate?
71
71
  Then(/^#{capture_model} should not (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
72
72
  model!(name).should_not send("be_#{predicate.gsub(' ', '_')}")
73
- end
73
+ end
74
+
75
+ # model.attribute.should eql(value)
76
+ # model.attribute.should_not eql(value)
77
+ Then(/^#{capture_model}'s (\w+) (should(?: not)?) be #{capture_value}$/) do |name, attribute, expectation, expected|
78
+ actual_value = model(name).send(attribute)
79
+ expectation = expectation.gsub(' ', '_')
80
+
81
+ case expected
82
+ when 'nil', 'true', 'false'
83
+ actual_value.send(expectation, send("be_#{expected}"))
84
+ when /^-?[0-9_]+$/
85
+ actual_value.send(expectation, eql(expected.to_i))
86
+ else
87
+ actual_value.to_s.send(expectation, eql(expected))
88
+ end
89
+ end
@@ -1,25 +1,25 @@
1
- # IMPORTANT: This file was generated by Cucumber 0.4.4
2
- # Edit at your own peril - it's recommended to regenerate this file
3
- # in the future when you upgrade to a newer version of Cucumber.
4
- # Consider adding your own code to a new file instead of editing this one.
1
+ # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2
+ # It is recommended to regenerate this file in the future when you upgrade to a
3
+ # newer version of cucumber-rails. Consider adding your own code to a new file
4
+ # instead of editing this one. Cucumber will automatically load all features/**/*.rb
5
+ # files.
5
6
 
6
- # Sets up the Rails environment for Cucumber
7
7
  ENV["RAILS_ENV"] ||= "cucumber"
8
8
  require File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
9
+
10
+ require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
9
11
  require 'cucumber/rails/world'
12
+ require 'cucumber/rails/active_record'
13
+ require 'cucumber/web/tableish'
14
+
15
+ require 'webrat'
16
+ require 'webrat/core/matchers'
17
+
18
+ Webrat.configure do |config|
19
+ config.mode = :rails
20
+ config.open_error_files = false # Set to true if you want error pages to pop up in the browser
21
+ end
10
22
 
11
- # If you set this to true, each scenario will run in a database transaction.
12
- # You can still turn off transactions on a per-scenario basis, simply tagging
13
- # a feature or scenario with the @no-txn tag.
14
- #
15
- # If you set this to false, transactions will be off for all scenarios,
16
- # regardless of whether you use @no-txn or not.
17
- #
18
- # Beware that turning transactions off will leave data in your database
19
- # after each scenario, which can lead to hard-to-debug failures in
20
- # subsequent scenarios. If you do this, we recommend you create a Before
21
- # block that will explicitly put your database in a known state.
22
- Cucumber::Rails::World.use_transactional_fixtures = true
23
23
 
24
24
  # If you set this to false, any error raised from within your app will bubble
25
25
  # up to your step definition and out to cucumber unless you catch it somewhere
@@ -32,16 +32,21 @@ Cucumber::Rails::World.use_transactional_fixtures = true
32
32
  # of your scenarios, as this makes it hard to discover errors in your application.
33
33
  ActionController::Base.allow_rescue = false
34
34
 
35
- require 'cucumber'
36
- # Comment out the next line if you don't want Cucumber Unicode support
37
- require 'cucumber/formatter/unicode'
38
- require 'cucumber/webrat/element_locator' # Lets you do table.diff!(element_at('#my_table_or_dl_or_ul_or_ol').to_table)
39
- require 'cucumber/rails/rspec'
40
-
41
- require 'webrat'
42
- require 'webrat/core/matchers'
43
- Webrat.configure do |config|
44
- config.mode = :rails
45
- config.open_error_files = false # Set to true if you want error pages to pop up in the browser
46
- end
35
+ # If you set this to true, each scenario will run in a database transaction.
36
+ # You can still turn off transactions on a per-scenario basis, simply tagging
37
+ # a feature or scenario with the @no-txn tag. If you are using Capybara,
38
+ # tagging with @culerity or @javascript will also turn transactions off.
39
+ #
40
+ # If you set this to false, transactions will be off for all scenarios,
41
+ # regardless of whether you use @no-txn or not.
42
+ #
43
+ # Beware that turning transactions off will leave data in your database
44
+ # after each scenario, which can lead to hard-to-debug failures in
45
+ # subsequent scenarios. If you do this, we recommend you create a Before
46
+ # block that will explicitly put your database in a known state.
47
+ Cucumber::Rails::World.use_transactional_fixtures = true
47
48
 
49
+ # How to clean your database when transactions are turned off. See
50
+ # http://github.com/bmabey/database_cleaner for more info.
51
+ require 'database_cleaner'
52
+ DatabaseCleaner.strategy = :truncation
@@ -3,7 +3,7 @@ module NavigationHelpers
3
3
  #
4
4
  # When /^I go to (.+)$/ do |page_name|
5
5
  #
6
- # step definition in webrat_steps.rb
6
+ # step definition in web_steps.rb
7
7
  #
8
8
  def path_to(page_name)
9
9
  case page_name
@@ -12,7 +12,7 @@ module NavigationHelpers
12
12
  '/'
13
13
 
14
14
  # Add more mappings here.
15
- # Here is a more fancy example:
15
+ # Here is an example that pulls values out of the Regexp:
16
16
  #
17
17
  # when /^(.*)'s profile page$/i
18
18
  # user_profile_path(User.find_by_login($1))
@@ -1,9 +1,3 @@
1
- # test app setup
2
- __APP__ = File.expand_path(File.join(File.dirname(__FILE__), '../app'))
3
- require "#{__APP__}/app"
4
- require "#{__APP__}/factories"
5
- require "#{__APP__}/blueprints"
6
-
7
1
  Pickle.configure do |c|
8
2
  c.map 'I', :to => 'user: "me"'
9
3
  c.map 'killah fork', :to => 'fancy fork: "of cornwood"'
data/garlic.rb CHANGED
@@ -5,6 +5,7 @@ garlic do
5
5
  repo 'factory_girl', :url => 'git://github.com/thoughtbot/factory_girl'
6
6
  repo 'machinist', :url => 'git://github.com/notahat/machinist'
7
7
  repo 'cucumber', :url => 'git://github.com/aslakhellesoy/cucumber'
8
+ repo 'cucumber-rails', :url => 'git://github.com/aslakhellesoy/cucumber-rails'
8
9
  repo 'webrat', :url => 'git://github.com/brynary/webrat'
9
10
  repo 'pickle', :path => '.'
10
11
 
@@ -18,11 +19,12 @@ garlic do
18
19
  `script/generate rspec -f`
19
20
  end
20
21
  plugin 'factory_girl'
21
- plugin 'cucumber' do
22
- `script/generate cucumber -f`
23
- end
22
+ plugin 'cucumber'
24
23
  plugin 'machinist'
25
24
  plugin 'webrat'
25
+ plugin 'cucumber-rails' do
26
+ `script/generate cucumber --webrat -f`
27
+ end
26
28
  end
27
29
 
28
30
  run do
data/lib/pickle/email.rb CHANGED
@@ -18,7 +18,17 @@ module Pickle
18
18
  end
19
19
  true
20
20
  end
21
-
21
+
22
+ def visit_in_email(email, link_text)
23
+ visit(parse_email_for_link(email, link_text))
24
+ end
25
+
26
+ def click_first_link_in_email(email)
27
+ link = links_in_email(email).first
28
+ request_uri = URI::parse(link).request_uri
29
+ visit request_uri
30
+ end
31
+
22
32
  protected
23
33
  # Saves the emails out to RAILS_ROOT/tmp/ and opens it in the default
24
34
  # web browser if on OS X. (depends on webrat)
@@ -32,5 +42,31 @@ module Pickle
32
42
  end
33
43
  open_in_browser(filename)
34
44
  end
45
+
46
+ def parse_email_for_link(email, text_or_regex)
47
+ url = parse_email_for_explicit_link(email, text_or_regex)
48
+ url ||= parse_email_for_anchor_text_link(email, text_or_regex)
49
+ raise "No link found matching #{text_or_regex.inspect} in #{email}" unless url
50
+ url
51
+ end
52
+
53
+ # e.g. confirm in http://confirm
54
+ def parse_email_for_explicit_link(email, regex)
55
+ regex = /#{Regexp.escape(regex)}/ unless regex.is_a?(Regexp)
56
+ url = links_in_email(email).detect { |link| link =~ regex }
57
+ URI::parse(url).request_uri if url
58
+ end
59
+
60
+ # e.g. Click here in <a href="http://confirm">Click here</a>
61
+ def parse_email_for_anchor_text_link(email, link_text)
62
+ email.body =~ %r{<a[^>]*href=['"]?([^'"]*)['"]?[^>]*?>[^<]*?#{link_text}[^<]*?</a>}
63
+ URI.split($~[1])[5..-1].compact!.join("?").gsub("&amp;", "&")
64
+ # sub correct ampersand after rails switches it (http://dev.rubyonrails.org/ticket/4002)
65
+ end
66
+
67
+ def links_in_email(email, protos=['http', 'https'])
68
+ URI.extract(email.body, protos)
69
+ end
70
+
35
71
  end
36
72
  end
data/lib/pickle/world.rb CHANGED
@@ -5,5 +5,5 @@ World(Pickle::Session)
5
5
 
6
6
  # shortcuts to regexps for use in step definition regexps
7
7
  class << self
8
- delegate :capture_model, :capture_fields, :capture_factory, :capture_plural_factory, :capture_predicate, :to => 'Pickle.parser'
8
+ delegate :capture_model, :capture_fields, :capture_factory, :capture_plural_factory, :capture_predicate, :capture_value, :to => 'Pickle.parser'
9
9
  end
data/pickle.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{pickle}
8
- s.version = "0.2.1"
8
+ s.version = "0.2.2"
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-12-01}
12
+ s.date = %q{2010-02-27}
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 = [
@@ -83,7 +83,7 @@ Gem::Specification.new do |s|
83
83
  s.homepage = %q{http://github.com/ianwhite/pickle/tree}
84
84
  s.rdoc_options = ["--charset=UTF-8"]
85
85
  s.require_paths = ["lib"]
86
- s.rubygems_version = %q{1.3.5}
86
+ s.rubygems_version = %q{1.3.6}
87
87
  s.summary = %q{Easy model creation and reference in your cucumber features}
88
88
  s.test_files = [
89
89
  "spec/lib/pickle_adapter_spec.rb",
@@ -108,3 +108,4 @@ Gem::Specification.new do |s|
108
108
  else
109
109
  end
110
110
  end
111
+
@@ -18,6 +18,14 @@ Given(/^(\d)+ emails? should be delivered$/) do |count|
18
18
  emails.size.should == count.to_i
19
19
  end
20
20
 
21
+ When(/^(?:I|they) follow "([^"]*?)" in #{capture_email}$/) do |link, email_ref|
22
+ visit_in_email(email(email_ref), link)
23
+ end
24
+
25
+ When(/^(?:I|they) click the first link in #{capture_email}$/) do |email_ref|
26
+ click_first_link_in_email(email(email_ref))
27
+ end
28
+
21
29
  Then(/^(\d)+ emails? should be delivered to (.*)$/) do |count, to|
22
30
  emails("to: \"#{email_for(to)}\"").size.should == count.to_i
23
31
  end
@@ -70,4 +70,20 @@ end
70
70
  # assert not model.predicate?
71
71
  Then(/^#{capture_model} should not (?:be|have) (?:an? )?#{capture_predicate}$/) do |name, predicate|
72
72
  model!(name).should_not send("be_#{predicate.gsub(' ', '_')}")
73
- end
73
+ end
74
+
75
+ # model.attribute.should eql(value)
76
+ # model.attribute.should_not eql(value)
77
+ Then(/^#{capture_model}'s (\w+) (should(?: not)?) be #{capture_value}$/) do |name, attribute, expectation, expected|
78
+ actual_value = model(name).send(attribute)
79
+ expectation = expectation.gsub(' ', '_')
80
+
81
+ case expected
82
+ when 'nil', 'true', 'false'
83
+ actual_value.send(expectation, send("be_#{expected}"))
84
+ when /^-?[0-9_]+$/
85
+ actual_value.send(expectation, eql(expected.to_i))
86
+ else
87
+ actual_value.to_s.send(expectation, eql(expected))
88
+ end
89
+ end
@@ -128,4 +128,26 @@ describe Pickle::Email do
128
128
  save_and_open_emails
129
129
  end
130
130
  end
131
+
132
+ describe "following links in emails" do
133
+ before do
134
+ stub!(:open_in_browser)
135
+ @email1.stub!(:body).and_return('some text <a href="http://example.com/page">example page</a> more text')
136
+ end
137
+
138
+ it "should find a link for http://example.com/page" do
139
+ should_receive(:visit).with('/page')
140
+ visit_in_email(@email1, 'http://example.com/page')
141
+ end
142
+
143
+ it "should find a link for \"example page\"" do
144
+ should_receive(:visit).with('/page')
145
+ visit_in_email(@email1, 'example page')
146
+ end
147
+
148
+ it "should follow the first link in an email" do
149
+ should_receive(:visit).with('/page')
150
+ click_first_link_in_email(@email1)
151
+ end
152
+ end
131
153
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pickle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 2
9
+ version: 0.2.2
5
10
  platform: ruby
6
11
  authors:
7
12
  - Ian White
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-12-01 00:00:00 +00:00
17
+ date: 2010-02-27 00:00:00 +00:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -98,18 +103,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
103
  requirements:
99
104
  - - ">="
100
105
  - !ruby/object:Gem::Version
106
+ segments:
107
+ - 0
101
108
  version: "0"
102
- version:
103
109
  required_rubygems_version: !ruby/object:Gem::Requirement
104
110
  requirements:
105
111
  - - ">="
106
112
  - !ruby/object:Gem::Version
113
+ segments:
114
+ - 0
107
115
  version: "0"
108
- version:
109
116
  requirements: []
110
117
 
111
118
  rubyforge_project:
112
- rubygems_version: 1.3.5
119
+ rubygems_version: 1.3.6
113
120
  signing_key:
114
121
  specification_version: 3
115
122
  summary: Easy model creation and reference in your cucumber features