Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generators for RSpec integration suite
+ Feature to check migrations after clearance:install + Create generator for intalling rspec specs + Updated readme for RSpec integration generator
- Loading branch information
Showing
21 changed files
with
395 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
Feature: add migrations to the project | ||
|
||
Background: | ||
Given I have a project with clearance | ||
And I run `bundle install --local` | ||
|
||
Scenario: Users table does not exist | ||
And I successfully run `bundle exec rails generate clearance:install` | ||
And I successfully run `ls db/migrate` | ||
Then the output should contain: | ||
""" | ||
create_users.rb | ||
""" | ||
|
||
Scenario: Users table without clearance fields exists in the database | ||
When I write to "db/migrate/001_create_users.rb" with: | ||
""" | ||
class CreateUsers < ActiveRecord::Migration | ||
def self.up | ||
create_table(:users) do |t| | ||
t.string :email | ||
t.string :name | ||
end | ||
end | ||
def self.down | ||
end | ||
end | ||
""" | ||
And I successfully run `bundle exec rake db:migrate --trace` | ||
And I successfully run `bundle exec rails generate clearance:install` | ||
And I successfully run `ls db/migrate` | ||
Then the output should contain: | ||
""" | ||
add_clearance_to_users.rb | ||
""" | ||
|
||
Scenario: Users table with clearance fields exists in the database | ||
When I write to "db/migrate/001_create_users.rb" with: | ||
""" | ||
class CreateUsers < ActiveRecord::Migration | ||
def self.up | ||
create_table :users do |t| | ||
t.timestamps :null => false | ||
t.string :email, :null => false | ||
t.string :encrypted_password, :limit => 128, :null => false | ||
t.string :confirmation_token, :limit => 128 | ||
t.string :remember_token, :limit => 128, :null => false | ||
end | ||
add_index :users, :email | ||
add_index :users, :remember_token | ||
end | ||
def self.down | ||
drop_table :users | ||
end | ||
end | ||
""" | ||
And I successfully run `bundle exec rake db:migrate --trace` | ||
And I successfully run `bundle exec rails generate clearance:install` | ||
And I successfully run `ls db/migrate` | ||
Then the output should not contain: | ||
""" | ||
add_clearance_to_users.rb | ||
""" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Feature: install and run cucumber features | ||
|
||
Background: | ||
Given I have a project with clearance and the following gems: | ||
| gem | | ||
| cucumber-rails | | ||
| capybara | | ||
| rspec-rails | | ||
| factory_girl_rails | | ||
| database_cleaner | | ||
And I run `bundle install --local` | ||
And I successfully run `bundle exec rails generate cucumber:install` | ||
And I successfully run `bundle exec rails generate clearance:features` | ||
And I successfully run `bundle exec rails generate clearance:install` | ||
|
||
Scenario: generate a Rails app, run the generators, and run the tests | ||
Then the output should contain "Next steps" | ||
When I successfully run `bundle exec rake db:migrate --trace` | ||
And I successfully run `bundle exec rake --trace` | ||
Then the output should contain "passed" | ||
And the output should not contain "failed" | ||
And the output should not contain "Could not find generator" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Feature: generate rspec integration tests with application | ||
|
||
Background: | ||
Given I have a project with clearance and the following gems: | ||
| gem | | ||
| capybara | | ||
| rspec-rails | | ||
| factory_girl_rails | | ||
| database_cleaner | | ||
And I run `bundle install --local` | ||
And I successfully run `bundle exec rails generate rspec:install` | ||
And I successfully run `bundle exec rails generate clearance:specs` | ||
|
||
Scenario: generate a Rails app, run the generators, and run the tests | ||
And I successfully run `bundle exec rails generate clearance:install` | ||
Then the output should contain "Next steps" | ||
When I successfully run `bundle exec rake db:migrate --trace` | ||
And I successfully run `bundle exec rspec` | ||
Then the output should contain "Finished" | ||
And the output should not contain "Failed examples" | ||
And the output should not contain "Could not find generator" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,6 @@ | |
|
||
factory :user do | ||
password "password" | ||
password 'password' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Description: | ||
Generate RSpec integration tests | ||
|
||
Examples: | ||
rails generate clearance:specs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'rails/generators/base' | ||
|
||
module Clearance | ||
module Generators | ||
class SpecsGenerator < Rails::Generators::Base | ||
source_root File.expand_path('../templates', __FILE__) | ||
|
||
def create_specs | ||
directory '.', 'spec' | ||
end | ||
end | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
lib/generators/clearance/specs/templates/factories/clearance.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FactoryGirl.define do | ||
sequence :email do |n| | ||
"user#{n}@example.com" | ||
end | ||
|
||
factory :user do | ||
password 'password' | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
lib/generators/clearance/specs/templates/integration/clearance/user_signs_out_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
require 'spec_helper' | ||
|
||
feature 'User signs out' do | ||
scenario 'signs out' do | ||
user = signed_in_user | ||
sign_out | ||
|
||
user_should_be_signed_out | ||
end | ||
end |
28 changes: 28 additions & 0 deletions
28
...enerators/clearance/specs/templates/integration/clearance/visitor_resets_password_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'spec_helper' | ||
|
||
feature 'Visitor resets password' do | ||
scenario 'with valid email' do | ||
user = user_with_reset_password | ||
|
||
page_should_display_change_password_message | ||
reset_notification_should_be_sent_to user | ||
end | ||
|
||
scenario 'with non-user account' do | ||
reset_password_for 'unknown.email@example.com' | ||
|
||
page_should_display_change_password_message | ||
mailer_should_have_no_deliveries | ||
end | ||
|
||
private | ||
|
||
def reset_notification_should_be_sent_to(user) | ||
user.confirmation_token.should_not be_blank | ||
mailer_should_have_delivery user.email, 'password', user.confirmation_token | ||
end | ||
|
||
def page_should_display_change_password_message | ||
page.should have_content('instructions for changing your password') | ||
end | ||
end |
42 changes: 42 additions & 0 deletions
42
lib/generators/clearance/specs/templates/integration/clearance/visitor_signs_in_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require 'spec_helper' | ||
|
||
feature 'Visitor signs in' do | ||
scenario 'with valid email and password' do | ||
create_user 'user@example.com', 'password' | ||
sign_in_with 'user@example.com', 'password' | ||
|
||
user_should_be_signed_in | ||
end | ||
|
||
scenario 'with valid mixed-case email and password ' do | ||
create_user 'user.name@example.com', 'password' | ||
sign_in_with 'User.Name@example.com', 'password' | ||
|
||
user_should_be_signed_in | ||
end | ||
|
||
scenario 'tries with invalid password' do | ||
create_user 'user@example.com', 'password' | ||
sign_in_with 'user@example.com', 'wrong_password' | ||
|
||
page_should_display_sign_in_error | ||
user_should_be_signed_out | ||
end | ||
|
||
scenario 'tries with invalid email' do | ||
sign_in_with 'unknown.email@example.com', 'password' | ||
|
||
page_should_display_sign_in_error | ||
user_should_be_signed_out | ||
end | ||
|
||
private | ||
|
||
def create_user(email, password) | ||
create(:user, :email => email, :password => password) | ||
end | ||
|
||
def page_should_display_sign_in_error | ||
page.should have_content('Bad email or password') | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
lib/generators/clearance/specs/templates/integration/clearance/visitor_signs_up_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'spec_helper' | ||
|
||
feature 'Visitor signs up' do | ||
scenario 'with valid email and password' do | ||
sign_up_with 'valid@example.com', 'password' | ||
|
||
user_should_be_signed_in | ||
end | ||
|
||
scenario 'tries with invalid email' do | ||
sign_up_with 'invalid_email', 'password' | ||
|
||
user_should_be_signed_out | ||
end | ||
|
||
scenario 'tries with blank password' do | ||
sign_up_with 'valid@example.com', '' | ||
|
||
user_should_be_signed_out | ||
end | ||
end |
Oops, something went wrong.