Skip to content

Commit

Permalink
add some specs/features for user sign up (from http://railsapps.githu…
Browse files Browse the repository at this point in the history
…b.io/)

Conflicts:
	config/routes.rb
  • Loading branch information
gdagley committed Jun 24, 2013
1 parent 6436db9 commit 9fc7f9b
Show file tree
Hide file tree
Showing 20 changed files with 666 additions and 28 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ end
group :test do
gem 'cucumber-rails', :require => false
gem 'database_cleaner'
gem 'email_spec'
end

guard_notifications = true
Expand Down
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ GEM
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
addressable (2.3.4)
annotate (2.5.0)
rake
arel (3.0.2)
Expand Down Expand Up @@ -89,6 +90,9 @@ GEM
em-websocket (0.5.0)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.5.3)
email_spec (1.4.0)
launchy (~> 2.1)
mail (~> 2.2)
erubis (2.7.0)
eventmachine (1.0.3)
excon (0.25.0)
Expand Down Expand Up @@ -153,6 +157,8 @@ GEM
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
kgio (2.8.0)
launchy (2.3.0)
addressable (~> 2.3)
letters (0.3.1)
activesupport
awesome_print
Expand Down Expand Up @@ -334,6 +340,7 @@ DEPENDENCIES
cucumber-rails
database_cleaner
devise
email_spec
factory_girl_rails
faker
font-awesome-sass-rails
Expand Down
10 changes: 5 additions & 5 deletions Guardfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ guard 'bundler' do
# watch(/^.+\.gemspec/)
end

# guard 'cucumber' do
# watch(%r{^features/.+\.feature$})
# watch(%r{^features/support/.+$}) { 'features' }
# watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
# end
guard 'cucumber' do
watch(%r{^features/.+\.feature$})
watch(%r{^features/support/.+$}) { 'features' }
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
end

guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)})
Expand Down
2 changes: 1 addition & 1 deletion config/cucumber.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
std_opts = "-r features/support/ -r features/step_definitions --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
%>
default: <%= std_opts %> features
wip: --tags @wip:3 --wip features
Expand Down
6 changes: 3 additions & 3 deletions config/initializers/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
# The time you want to timeout the user session without activity. After this
# time the user will be asked for credentials again. Default is 30 minutes.
# config.timeout_in = 30.minutes

# If true, expires auth token on session timeout.
# config.expire_auth_token_on_timeout = false

Expand Down Expand Up @@ -200,7 +200,7 @@
# config.navigational_formats = ["*/*", :html]

# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete
config.sign_out_via = Rails.env.test? ? :get : :delete

# ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting
Expand Down Expand Up @@ -229,4 +229,4 @@
# When using omniauth, Devise cannot automatically set Omniauth path,
# so you need to do it manually. For the users scope, it would be:
# config.omniauth_path_prefix = "/my_engine/users/auth"
end
end
5 changes: 3 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
BaseJumper::Application.routes.draw do
authenticated :user do
root :to => 'home#index'
end
root :to => 'home#index'

get "home/index"

mount RailsAdmin::Engine => '/admin', :as => 'rails_admin'

devise_for :users
Expand Down
206 changes: 206 additions & 0 deletions features/step_definitions/email_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
# Commonly used email steps
#
# To add your own steps make a custom_email_steps.rb
# The provided methods are:
#
# last_email_address
# reset_mailer
# open_last_email
# visit_in_email
# unread_emails_for
# mailbox_for
# current_email
# open_email
# read_emails_for
# find_email
#
# General form for email scenarios are:
# - clear the email queue (done automatically by email_spec)
# - execute steps that sends an email
# - check the user received an/no/[0-9] emails
# - open the email
# - inspect the email contents
# - interact with the email (e.g. click links)
#
# The Cucumber steps below are setup in this order.

module EmailHelpers
def current_email_address
# Replace with your a way to find your current email. e.g @current_user.email
# last_email_address will return the last email address used by email spec to find an email.
# Note that last_email_address will be reset after each Scenario.
last_email_address || "example@example.com"
end
end

World(EmailHelpers)

#
# Reset the e-mail queue within a scenario.
# This is done automatically before each scenario.
#

Given /^(?:a clear email queue|no emails have been sent)$/ do
reset_mailer
end

#
# Check how many emails have been sent/received
#

Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails?$/ do |address, amount|
unread_emails_for(address).size.should == parse_email_count(amount)
end

Then /^(?:I|they|"([^"]*?)") should have (an|no|\d+) emails?$/ do |address, amount|
mailbox_for(address).size.should == parse_email_count(amount)
end

Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject "([^"]*?)"$/ do |address, amount, subject|
unread_emails_for(address).select { |m| m.subject =~ Regexp.new(Regexp.escape(subject)) }.size.should == parse_email_count(amount)
end

Then /^(?:I|they|"([^"]*?)") should receive (an|no|\d+) emails? with subject \/([^"]*?)\/$/ do |address, amount, subject|
unread_emails_for(address).select { |m| m.subject =~ Regexp.new(subject) }.size.should == parse_email_count(amount)
end

Then /^(?:I|they|"([^"]*?)") should receive an email with the following body:$/ do |address, expected_body|
open_email(address, :with_text => expected_body)
end

#
# Accessing emails
#

# Opens the most recently received email
When /^(?:I|they|"([^"]*?)") opens? the email$/ do |address|
open_email(address)
end

When /^(?:I|they|"([^"]*?)") opens? the email with subject "([^"]*?)"$/ do |address, subject|
open_email(address, :with_subject => subject)
end

When /^(?:I|they|"([^"]*?)") opens? the email with subject \/([^"]*?)\/$/ do |address, subject|
open_email(address, :with_subject => Regexp.new(subject))
end

When /^(?:I|they|"([^"]*?)") opens? the email with text "([^"]*?)"$/ do |address, text|
open_email(address, :with_text => text)
end

When /^(?:I|they|"([^"]*?)") opens? the email with text \/([^"]*?)\/$/ do |address, text|
open_email(address, :with_text => Regexp.new(text))
end

#
# Inspect the Email Contents
#

Then /^(?:I|they) should see "([^"]*?)" in the email subject$/ do |text|
current_email.should have_subject(text)
end

Then /^(?:I|they) should see \/([^"]*?)\/ in the email subject$/ do |text|
current_email.should have_subject(Regexp.new(text))
end

Then /^(?:I|they) should see "([^"]*?)" in the email body$/ do |text|
current_email.default_part_body.to_s.should include(text)
end

Then /^(?:I|they) should see \/([^"]*?)\/ in the email body$/ do |text|
current_email.default_part_body.to_s.should =~ Regexp.new(text)
end

Then /^(?:I|they) should see the email delivered from "([^"]*?)"$/ do |text|
current_email.should be_delivered_from(text)
end

Then /^(?:I|they) should see "([^\"]*)" in the email "([^"]*?)" header$/ do |text, name|
current_email.should have_header(name, text)
end

Then /^(?:I|they) should see \/([^\"]*)\/ in the email "([^"]*?)" header$/ do |text, name|
current_email.should have_header(name, Regexp.new(text))
end

Then /^I should see it is a multi\-part email$/ do
current_email.should be_multipart
end

Then /^(?:I|they) should see "([^"]*?)" in the email html part body$/ do |text|
current_email.html_part.body.to_s.should include(text)
end

Then /^(?:I|they) should see "([^"]*?)" in the email text part body$/ do |text|
current_email.text_part.body.to_s.should include(text)
end

#
# Inspect the Email Attachments
#

Then /^(?:I|they) should see (an|no|\d+) attachments? with the email$/ do |amount|
current_email_attachments.size.should == parse_email_count(amount)
end

Then /^there should be (an|no|\d+) attachments? named "([^"]*?)"$/ do |amount, filename|
current_email_attachments.select { |a| a.filename == filename }.size.should == parse_email_count(amount)
end

Then /^attachment (\d+) should be named "([^"]*?)"$/ do |index, filename|
current_email_attachments[(index.to_i - 1)].filename.should == filename
end

Then /^there should be (an|no|\d+) attachments? of type "([^"]*?)"$/ do |amount, content_type|
current_email_attachments.select { |a| a.content_type.include?(content_type) }.size.should == parse_email_count(amount)
end

Then /^attachment (\d+) should be of type "([^"]*?)"$/ do |index, content_type|
current_email_attachments[(index.to_i - 1)].content_type.should include(content_type)
end

Then /^all attachments should not be blank$/ do
current_email_attachments.each do |attachment|
attachment.read.size.should_not == 0
end
end

Then /^show me a list of email attachments$/ do
EmailSpec::EmailViewer::save_and_open_email_attachments_list(current_email)
end

#
# Interact with Email Contents
#

When /^(?:I|they) follow "([^"]*?)" in the email$/ do |link|
visit_in_email(link)
end

When /^(?:I|they) click the first link in the email$/ do
click_first_link_in_email
end

#
# Debugging
# These only work with Rails and OSx ATM since EmailViewer uses RAILS_ROOT and OSx's 'open' command.
# Patches accepted. ;)
#

Then /^save and open current email$/ do
EmailSpec::EmailViewer::save_and_open_email(current_email)
end

Then /^save and open all text emails$/ do
EmailSpec::EmailViewer::save_and_open_all_text_emails
end

Then /^save and open all html emails$/ do
EmailSpec::EmailViewer::save_and_open_all_html_emails
end

Then /^save and open all raw emails$/ do
EmailSpec::EmailViewer::save_and_open_all_raw_emails
end
Loading

0 comments on commit 9fc7f9b

Please sign in to comment.