email_spec 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +79 -0
- data/MIT-LICENSE.txt +19 -0
- data/README.rdoc +125 -0
- data/Rakefile +51 -0
- data/examples/rails_root/Rakefile +7 -0
- data/examples/rails_root/app/controllers/application.rb +15 -0
- data/examples/rails_root/app/controllers/welcome_controller.rb +9 -0
- data/examples/rails_root/app/helpers/application_helper.rb +3 -0
- data/examples/rails_root/app/helpers/welcome_helper.rb +2 -0
- data/examples/rails_root/app/models/user.rb +2 -0
- data/examples/rails_root/app/models/user_mailer.rb +12 -0
- data/examples/rails_root/app/views/user_mailer/signup.erb +3 -0
- data/examples/rails_root/app/views/welcome/confirm.html.erb +1 -0
- data/examples/rails_root/app/views/welcome/index.html.erb +8 -0
- data/examples/rails_root/app/views/welcome/signup.html.erb +1 -0
- data/examples/rails_root/config/boot.rb +109 -0
- data/examples/rails_root/config/database.yml +22 -0
- data/examples/rails_root/config/environment.rb +22 -0
- data/examples/rails_root/config/environments/development.rb +17 -0
- data/examples/rails_root/config/environments/production.rb +24 -0
- data/examples/rails_root/config/environments/test.rb +33 -0
- data/examples/rails_root/config/initializers/inflections.rb +10 -0
- data/examples/rails_root/config/initializers/mime_types.rb +5 -0
- data/examples/rails_root/config/initializers/new_rails_defaults.rb +17 -0
- data/examples/rails_root/config/routes.rb +43 -0
- data/examples/rails_root/cucumber.yml +1 -0
- data/examples/rails_root/db/migrate/20090125013728_create_users.rb +11 -0
- data/examples/rails_root/db/schema.rb +19 -0
- data/examples/rails_root/doc/README_FOR_APP +5 -0
- data/examples/rails_root/features/errors.feature +42 -0
- data/examples/rails_root/features/example.feature +59 -0
- data/examples/rails_root/features/step_definitions/email_steps.rb +74 -0
- data/examples/rails_root/features/step_definitions/user_steps.rb +23 -0
- data/examples/rails_root/features/step_definitions/webrat_steps.rb +104 -0
- data/examples/rails_root/features/support/env.rb +21 -0
- data/examples/rails_root/log/development.log +1 -0
- data/examples/rails_root/log/test.log +224 -0
- data/examples/rails_root/public/404.html +30 -0
- data/examples/rails_root/public/422.html +30 -0
- data/examples/rails_root/public/500.html +33 -0
- data/examples/rails_root/public/dispatch.rb +10 -0
- data/examples/rails_root/public/favicon.ico +0 -0
- data/examples/rails_root/public/images/rails.png +0 -0
- data/examples/rails_root/public/javascripts/application.js +2 -0
- data/examples/rails_root/public/javascripts/controls.js +963 -0
- data/examples/rails_root/public/javascripts/dragdrop.js +973 -0
- data/examples/rails_root/public/javascripts/effects.js +1128 -0
- data/examples/rails_root/public/javascripts/prototype.js +4320 -0
- data/examples/rails_root/public/robots.txt +5 -0
- data/examples/rails_root/script/about +4 -0
- data/examples/rails_root/script/autospec +5 -0
- data/examples/rails_root/script/console +3 -0
- data/examples/rails_root/script/cucumber +7 -0
- data/examples/rails_root/script/dbconsole +3 -0
- data/examples/rails_root/script/destroy +3 -0
- data/examples/rails_root/script/generate +3 -0
- data/examples/rails_root/script/performance/benchmarker +3 -0
- data/examples/rails_root/script/performance/profiler +3 -0
- data/examples/rails_root/script/performance/request +3 -0
- data/examples/rails_root/script/plugin +3 -0
- data/examples/rails_root/script/process/inspector +3 -0
- data/examples/rails_root/script/process/reaper +3 -0
- data/examples/rails_root/script/process/spawner +3 -0
- data/examples/rails_root/script/runner +3 -0
- data/examples/rails_root/script/server +3 -0
- data/examples/rails_root/script/spec +5 -0
- data/examples/rails_root/script/spec_server +125 -0
- data/examples/rails_root/spec/controllers/welcome_controller_spec.rb +15 -0
- data/examples/rails_root/spec/model_factory.rb +6 -0
- data/examples/rails_root/spec/models/user_mailer_spec.rb +58 -0
- data/examples/rails_root/spec/models/user_spec.rb +5 -0
- data/examples/rails_root/spec/rcov.opts +2 -0
- data/examples/rails_root/spec/spec.opts +4 -0
- data/examples/rails_root/spec/spec_helper.rb +51 -0
- data/examples/rails_root/stories/all.rb +4 -0
- data/examples/rails_root/stories/helper.rb +3 -0
- data/examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/email_spec_generator.rb +17 -0
- data/examples/rails_root/vendor/plugins/email_spec/rails_generators/email_spec/templates/email_steps.rb +74 -0
- data/install.rb +0 -0
- data/lib/email-spec.rb +1 -0
- data/lib/email_spec.rb +14 -0
- data/lib/email_spec/address_converter.rb +27 -0
- data/lib/email_spec/cucumber.rb +19 -0
- data/lib/email_spec/deliveries.rb +55 -0
- data/lib/email_spec/email_viewer.rb +70 -0
- data/lib/email_spec/helpers.rb +129 -0
- data/lib/email_spec/matchers.rb +122 -0
- data/rails_generators/email_spec/email_spec_generator.rb +17 -0
- data/rails_generators/email_spec/templates/email_steps.rb +74 -0
- data/spec/email_spec/matchers_spec.rb +159 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +4 -0
- metadata +181 -0
@@ -0,0 +1,5 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
ENV['RSPEC'] = 'true' # allows autotest to discover rspec
|
3
|
+
ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
|
4
|
+
system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
|
5
|
+
$stderr.puts("Unable to find autotest. Please install ZenTest or fix your PATH")
|
@@ -0,0 +1,125 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin
|
3
|
+
require 'rubygems'
|
4
|
+
require 'drb/drb'
|
5
|
+
require 'rbconfig'
|
6
|
+
require 'spec'
|
7
|
+
require 'optparse'
|
8
|
+
|
9
|
+
# This is based on Florian Weber's TDDMate
|
10
|
+
module Spec
|
11
|
+
module Runner
|
12
|
+
class RailsSpecServer
|
13
|
+
def run(argv, stderr, stdout)
|
14
|
+
$stdout = stdout
|
15
|
+
$stderr = stderr
|
16
|
+
|
17
|
+
unless ActiveRecord::Base.respond_to?(:clear_reloadable_connections!)
|
18
|
+
base = ActiveRecord::Base
|
19
|
+
def base.clear_reloadable_connections!
|
20
|
+
active_connections.each do |name, conn|
|
21
|
+
if conn.requires_reloading?
|
22
|
+
conn.disconnect!
|
23
|
+
active_connections.delete(name)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
ActiveRecord::Base.clear_reloadable_connections!
|
30
|
+
|
31
|
+
if ActionController.const_defined?(:Dispatcher)
|
32
|
+
dispatcher = ::ActionController::Dispatcher.new($stdout)
|
33
|
+
dispatcher.cleanup_application
|
34
|
+
elsif ::Dispatcher.respond_to?(:reset_application!)
|
35
|
+
::Dispatcher.reset_application!
|
36
|
+
else
|
37
|
+
raise "Application reloading failed"
|
38
|
+
end
|
39
|
+
if Object.const_defined?(:Fixtures) && Fixtures.respond_to?(:reset_cache)
|
40
|
+
Fixtures.reset_cache
|
41
|
+
end
|
42
|
+
|
43
|
+
if ::ActiveSupport.const_defined?(:Dependencies)
|
44
|
+
::ActiveSupport::Dependencies.mechanism = :load
|
45
|
+
else
|
46
|
+
::Dependencies.mechanism = :load
|
47
|
+
end
|
48
|
+
|
49
|
+
require_dependency('application.rb') unless Object.const_defined?(:ApplicationController)
|
50
|
+
load File.dirname(__FILE__) + '/../spec/spec_helper.rb'
|
51
|
+
|
52
|
+
if in_memory_database?
|
53
|
+
load "#{RAILS_ROOT}/db/schema.rb" # use db agnostic schema by default
|
54
|
+
ActiveRecord::Migrator.up('db/migrate') # use migrations
|
55
|
+
end
|
56
|
+
|
57
|
+
::Spec::Runner::CommandLine.run(
|
58
|
+
::Spec::Runner::OptionParser.parse(
|
59
|
+
argv,
|
60
|
+
$stderr,
|
61
|
+
$stdout
|
62
|
+
)
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def in_memory_database?
|
67
|
+
ENV["RAILS_ENV"] == "test" and
|
68
|
+
::ActiveRecord::Base.connection.class.to_s == "ActiveRecord::ConnectionAdapters::SQLite3Adapter" and
|
69
|
+
::Rails::Configuration.new.database_configuration['test']['database'] == ':memory:'
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
puts "Loading Rails environment"
|
75
|
+
|
76
|
+
ENV["RAILS_ENV"] = "test"
|
77
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
78
|
+
require 'dispatcher'
|
79
|
+
|
80
|
+
def restart_test_server
|
81
|
+
puts "restarting"
|
82
|
+
config = ::Config::CONFIG
|
83
|
+
ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
|
84
|
+
command_line = [ruby, $0, ARGV].flatten.join(' ')
|
85
|
+
exec(command_line)
|
86
|
+
end
|
87
|
+
|
88
|
+
def daemonize(pid_file = nil)
|
89
|
+
return yield if $DEBUG
|
90
|
+
pid = Process.fork{
|
91
|
+
Process.setsid
|
92
|
+
Dir.chdir(RAILS_ROOT)
|
93
|
+
trap("SIGINT"){ exit! 0 }
|
94
|
+
trap("SIGTERM"){ exit! 0 }
|
95
|
+
trap("SIGHUP"){ restart_test_server }
|
96
|
+
File.open("/dev/null"){|f|
|
97
|
+
STDERR.reopen f
|
98
|
+
STDIN.reopen f
|
99
|
+
STDOUT.reopen f
|
100
|
+
}
|
101
|
+
yield
|
102
|
+
}
|
103
|
+
puts "spec_server launched. (PID: %d)" % pid
|
104
|
+
File.open(pid_file,"w"){|f| f.puts pid } if pid_file
|
105
|
+
exit! 0
|
106
|
+
end
|
107
|
+
|
108
|
+
options = Hash.new
|
109
|
+
opts = OptionParser.new
|
110
|
+
opts.on("-d", "--daemon"){|v| options[:daemon] = true }
|
111
|
+
opts.on("-p", "--pid PIDFILE"){|v| options[:pid] = v }
|
112
|
+
opts.parse!(ARGV)
|
113
|
+
|
114
|
+
puts "Ready"
|
115
|
+
exec_server = lambda {
|
116
|
+
trap("USR2") { restart_test_server } if Signal.list.has_key?("USR2")
|
117
|
+
DRb.start_service("druby://127.0.0.1:8989", Spec::Runner::RailsSpecServer.new)
|
118
|
+
DRb.thread.join
|
119
|
+
}
|
120
|
+
|
121
|
+
if options[:daemon]
|
122
|
+
daemonize(options[:pid], &exec_server)
|
123
|
+
else
|
124
|
+
exec_server.call
|
125
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe WelcomeController do
|
4
|
+
|
5
|
+
describe "POST /signup (#signup)" do
|
6
|
+
it "should deliver the signup email" do
|
7
|
+
# expect
|
8
|
+
UserMailer.should_receive(:deliver_signup).with("email@example.com", "Jimmy Bean")
|
9
|
+
# when
|
10
|
+
post :signup, "Email" => "email@example.com", "Name" => "Jimmy Bean"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
# These two example groups are specifying the exact same behavior. However, the documentation style is different
|
4
|
+
# and the value that each one provides is different with various trade-offs. Run these examples with the specdoc
|
5
|
+
# formatter to get an idea of how they differ.
|
6
|
+
|
7
|
+
# Example of documenting the behaviour explicitly and expressing the intent in the example's sentence.
|
8
|
+
describe "Signup Email" do
|
9
|
+
include EmailSpec::Helpers
|
10
|
+
include EmailSpec::Matchers
|
11
|
+
include ActionController::UrlWriter
|
12
|
+
|
13
|
+
before(:all) do
|
14
|
+
@email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
15
|
+
end
|
16
|
+
|
17
|
+
subject { @email }
|
18
|
+
|
19
|
+
it "should be delivered to the email passed in" do
|
20
|
+
should deliver_to("jojo@yahoo.com")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should contain the user's name in the mail body" do
|
24
|
+
@email.should have_body_text(/Jojo Binks/)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should contain a link to the confirmation page" do
|
28
|
+
@email.should have_body_text(/#{confirm_account_url}/)
|
29
|
+
end
|
30
|
+
|
31
|
+
it { should have_subject(/Account confirmation/) }
|
32
|
+
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
# In this example group more of the documentation is placed in the context trying to allow for more concise specs.
|
37
|
+
describe "Signup Email" do
|
38
|
+
include EmailSpec::Helpers
|
39
|
+
include EmailSpec::Matchers
|
40
|
+
include ActionController::UrlWriter
|
41
|
+
|
42
|
+
before(:all) do
|
43
|
+
@email = UserMailer.create_signup("jojo@yahoo.com", "Jojo Binks")
|
44
|
+
end
|
45
|
+
|
46
|
+
subject { @email }
|
47
|
+
|
48
|
+
it { should have_body_text(/#{confirm_account_url}/) }
|
49
|
+
it { should have_subject(/Account confirmation/) }
|
50
|
+
|
51
|
+
describe "sent with email address of 'jojo@yahoo.com', and users name 'Jojo Binks'" do
|
52
|
+
subject { @email }
|
53
|
+
it { should deliver_to("jojo@yahoo.com") }
|
54
|
+
it { should have_body_text(/Jojo Binks/) }
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
2
|
+
# from the project root directory.
|
3
|
+
ENV["RAILS_ENV"] = "test"
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
5
|
+
require 'spec'
|
6
|
+
require 'spec/rails'
|
7
|
+
|
8
|
+
require File.expand_path(File.dirname(__FILE__) + "/model_factory.rb")
|
9
|
+
require (Rails.root + '/../../lib/email_spec.rb')
|
10
|
+
|
11
|
+
Spec::Runner.configure do |config|
|
12
|
+
config.include(Fixjour)
|
13
|
+
# If you're not using ActiveRecord you should remove these
|
14
|
+
# lines, delete config/database.yml and disable :active_record
|
15
|
+
# in your config/boot.rb
|
16
|
+
#config.use_transactional_fixtures = true
|
17
|
+
#config.use_instantiated_fixtures = false
|
18
|
+
#config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
|
19
|
+
|
20
|
+
# == Fixtures
|
21
|
+
#
|
22
|
+
# You can declare fixtures for each example_group like this:
|
23
|
+
# describe "...." do
|
24
|
+
# fixtures :table_a, :table_b
|
25
|
+
#
|
26
|
+
# Alternatively, if you prefer to declare them only once, you can
|
27
|
+
# do so right here. Just uncomment the next line and replace the fixture
|
28
|
+
# names with your fixtures.
|
29
|
+
#
|
30
|
+
# config.global_fixtures = :table_a, :table_b
|
31
|
+
#
|
32
|
+
# If you declare global fixtures, be aware that they will be declared
|
33
|
+
# for all of your examples, even those that don't use them.
|
34
|
+
#
|
35
|
+
# You can also declare which fixtures to use (for example fixtures for test/fixtures):
|
36
|
+
#
|
37
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
|
38
|
+
#
|
39
|
+
# == Mock Framework
|
40
|
+
#
|
41
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
42
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
43
|
+
#
|
44
|
+
# config.mock_with :mocha
|
45
|
+
# config.mock_with :flexmock
|
46
|
+
# config.mock_with :rr
|
47
|
+
#
|
48
|
+
# == Notes
|
49
|
+
#
|
50
|
+
# For more information take a look at Spec::Runner::Configuration and Spec::Runner
|
51
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This generator adds email steps to the step definitions directory
|
2
|
+
generator_base = defined?(Rails) ? Rails::Generator::Base : RubiGen::Base
|
3
|
+
class EmailSpecGenerator < generator_base
|
4
|
+
def manifest
|
5
|
+
record do |m|
|
6
|
+
m.directory 'features/step_definitions'
|
7
|
+
m.file 'email_steps.rb', 'features/step_definitions/email_steps.rb'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def banner
|
14
|
+
"Usage: #{$0} email_spec"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#Commonly used email steps
|
2
|
+
#
|
3
|
+
# To add your own steps make a custom_email_steps.rb
|
4
|
+
# The provided methods are:
|
5
|
+
#
|
6
|
+
# reset_mailer
|
7
|
+
# open_last_email
|
8
|
+
# visit_in_email
|
9
|
+
# unread_emails_for
|
10
|
+
# mailbox_for
|
11
|
+
# current_email
|
12
|
+
# open_email
|
13
|
+
# read_emails_for
|
14
|
+
# find_email
|
15
|
+
|
16
|
+
module EmailHelpers
|
17
|
+
def current_email_address
|
18
|
+
"quentin@example.com" # Replace with your a way to find your current_email. e.g current_user.email
|
19
|
+
end
|
20
|
+
end
|
21
|
+
World(EmailHelpers)
|
22
|
+
|
23
|
+
# Use this step to reset the e-mail queue within a scenario.
|
24
|
+
# This is done automatically before each scenario.
|
25
|
+
Given /^(?:a clear email queue|no emails have been sent)$/ do
|
26
|
+
reset_mailer
|
27
|
+
end
|
28
|
+
|
29
|
+
# Use this step to open the most recently sent e-mail.
|
30
|
+
When /^I open the email$/ do
|
31
|
+
open_email(current_email_address)
|
32
|
+
end
|
33
|
+
|
34
|
+
When %r{^I follow "([^"]*?)" in the email$} do |link|
|
35
|
+
visit_in_email(link)
|
36
|
+
end
|
37
|
+
|
38
|
+
Then /^I should receive (an|\d+) emails?$/ do |amount|
|
39
|
+
amount = 1 if amount == "an"
|
40
|
+
unread_emails_for(current_email_address).size.should == amount.to_i
|
41
|
+
end
|
42
|
+
|
43
|
+
Then %r{^"([^"]*?)" should receive (\d+) emails?$} do |address, n|
|
44
|
+
unread_emails_for(address).size.should == n.to_i
|
45
|
+
end
|
46
|
+
|
47
|
+
Then %r{^"([^"]*?)" should have (\d+) emails?$} do |address, n|
|
48
|
+
mailbox_for(address).size.should == n.to_i
|
49
|
+
end
|
50
|
+
|
51
|
+
Then %r{^"([^"]*?)" should not receive an email$} do |address|
|
52
|
+
find_email(address).should be_nil
|
53
|
+
end
|
54
|
+
|
55
|
+
Then %r{^I should see "([^"]*?)" in the subject$} do |text|
|
56
|
+
current_email.should have_subject(Regexp.new(text))
|
57
|
+
end
|
58
|
+
|
59
|
+
Then %r{^I should see "([^"]*?)" in the email$} do |text|
|
60
|
+
current_email.body.should =~ Regexp.new(text)
|
61
|
+
end
|
62
|
+
|
63
|
+
When %r{^"([^"]*?)" opens? the email with subject "([^"]*?)"$} do |address, subject|
|
64
|
+
open_email(address, :with_subject => subject)
|
65
|
+
end
|
66
|
+
|
67
|
+
When %r{^"([^"]*?)" opens? the email with text "([^"]*?)"$} do |address, text|
|
68
|
+
open_email(address, :with_text => text)
|
69
|
+
end
|
70
|
+
|
71
|
+
When /^I click the first link in the email$/ do
|
72
|
+
click_first_link_in_email
|
73
|
+
end
|
74
|
+
|