Skip to content

Commit

Permalink
Reorganized specs into specs/unit_tests and specs/acceptance_tests di…
Browse files Browse the repository at this point in the history
…rectories. Added metadata to all tests to let rspec-rails know the type of each test suite (controller, model, feature etc).

Older rspec-rails versions demanded a particular directory structure for the specs, so that e.g. controllers tests (which had to be in /specs/controllers) had a module mixed in during testing, to enable helper methods necessary for each type of test (e.g. accessing response headers directly during controller tests).

This is being deprecated and it will become opt-in in rspec-rails 3. A particular directory structure will no longer be enforced, each test suite will have to specify the type of test by using metadata (a :type named argument to the "describe" method at the top of each file).

I've gone ahead and, in preparation for rspec-rails 3, I've added metadata to all tests which make use of rspec-rails helper methods. Now that a particular directory structure is no longer enforced, I've reorganized tests in a "unit_tests" and "acceptance_tests" structure which is more confortable for me.

For details about the old directory structure and the new metadata-based spect type specification, see:

https://relishapp.com/rspec/rspec-rails/v/3-0/docs/directory-structure

For interesting discussions about this topic see:

rspec/rspec-rails#662
https://github.com/rspec/rspec-rails/pull/970/files
rspec/rspec-rails#1002
  • Loading branch information
amatriain committed Jun 3, 2014
1 parent 0858ec5 commit 9f87139
Show file tree
Hide file tree
Showing 67 changed files with 52 additions and 52 deletions.
6 changes: 3 additions & 3 deletions lib/tasks/rspec.rake
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ if Rails.env=='ci'
desc 'Run tests depending on the TEST_SUITE env variable: "unit"=>unit tests, "acceptance"=>acceptance tests'
RSpec::Core::RakeTask.new(:travisci) do |task|
all_tests = FileList['spec/**/*_spec.rb']
unit_tests = FileList['spec/**/*_spec.rb'].exclude 'spec/features/**/*_spec.rb'
acceptance_tests_1 = FileList['spec/features/suite_1/**/*_spec.rb']
acceptance_tests_2 = FileList['spec/features/suite_2/**/*_spec.rb']
unit_tests = FileList['spec/unit_tests/**/*_spec.rb']
acceptance_tests_1 = FileList['spec/acceptance_tests/suite_1/**/*_spec.rb']
acceptance_tests_2 = FileList['spec/acceptance_tests/suite_2/**/*_spec.rb']

if ENV['TEST_SUITE'] == 'unit'
# Include only unit tests
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'automatically closing notices and alerts' do
describe 'automatically closing notices and alerts', type: :feature do
before :each do
@user = FactoryGirl.create :user
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'authentication' do
describe 'authentication', type: :feature do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'authorization' do
describe 'authorization', type: :feature do

before :each do
@normal_user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'export subscriptions' do
describe 'export subscriptions', type: :feature do
before :each do
@user = FactoryGirl.create :user
@feed = FactoryGirl.create :feed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'feeds' do
describe 'feeds', type: :feature do

it 'redirects unauthenticated visitors to login page' do
visit read_path
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'folders and feeds' do
describe 'folders and feeds', type: :feature do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'refresh feeds' do
describe 'refresh feeds', type: :feature do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'start page' do
describe 'start page', type: :feature do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'feed entries' do
describe 'feed entries', type: :feature do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'subscription to feeds' do
describe 'subscription to feeds', type: :feature do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'unsubscribe from feed' do
describe 'unsubscribe from feed', type: :feature do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'import subscriptions' do
describe 'import subscriptions', type: :feature do
before :each do
@data_file = File.join __dir__, '..', '..', 'attachments', '[email protected]'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'quick reading mode' do
describe 'quick reading mode', type: :feature do

context 'mark entries open when scrolling' do

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'unread entries count' do
describe 'unread entries count', type: :feature do

before :each do
@user = FactoryGirl.create :user
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Api::EntriesController do
describe Api::EntriesController, type: :controller do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Api::FeedsController do
describe Api::FeedsController, type: :controller do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Api::FoldersController do
describe Api::FoldersController, type: :controller do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Api::OpmlExportsController do
describe Api::OpmlExportsController, type: :controller do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Api::OpmlImportsController do
describe Api::OpmlImportsController, type: :controller do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Devise::ProfilesController do
describe Devise::ProfilesController, type: :controller do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe ReadController do
describe ReadController, type: :controller do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Api::RefreshFeedJobStatesController do
describe Api::RefreshFeedJobStatesController, type: :controller do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Api::SubscribeJobStatesController do
describe Api::SubscribeJobStatesController, type: :controller do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Api::UserConfigsController do
describe Api::UserConfigsController, type: :controller do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Api::UserDataController do
describe Api::UserDataController, type: :controller do

before :each do
@user = FactoryGirl.create :user
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe DeletedEntry do
describe DeletedEntry, type: :model do

before :each do
@deleted_entry = FactoryGirl.create :deleted_entry
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Entry do
describe Entry, type: :model do

before :each do
@entry = FactoryGirl.create :entry
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe EntryState do
describe EntryState, type: :model do

context 'validations' do

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Feed do
describe Feed, type: :model do

before :each do
@feed = FactoryGirl.create :feed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe FeedSubscription do
describe FeedSubscription, type: :model do

before :each do
@feed_subscription = FactoryGirl.create :feed_subscription
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe Folder do
describe Folder, type: :model do
before :each do
@user = FactoryGirl.create :user
@folder = FactoryGirl.build :folder, user_id: @user.id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe OpmlExportJobState do
describe OpmlExportJobState, type: :model do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe OpmlImportJobState do
describe OpmlImportJobState, type: :model do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe RefreshFeedJobState do
describe RefreshFeedJobState, type: :model do

context 'validations' do

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe SubscribeJobState do
describe SubscribeJobState, type: :model do

context 'validations' do

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe User do
describe User, type: :model do
before :each do
@user = FactoryGirl.create :user
@feed = FactoryGirl.create :feed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe User do
describe User, type: :model do
before :each do
@user = FactoryGirl.create :user
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe User do
describe User, type: :model do
before :each do
@user = FactoryGirl.create :user
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe User do
describe User, type: :model do
before :each do
@user = FactoryGirl.create :user
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe User do
describe User, type: :model do
before :each do
@user = FactoryGirl.create :user
@folder = FactoryGirl.build :folder, user_id: @user.id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe User do
describe User, type: :model do
before :each do
@user = FactoryGirl.create :user
@feed = FactoryGirl.create :feed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe User do
describe User, type: :model do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe User do
describe User, type: :model do
before :each do
@user = FactoryGirl.create :user
@feed = FactoryGirl.create :feed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe User do
describe User, type: :model do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe User do
describe User, type: :model do

before :each do
@user = FactoryGirl.create :user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe User do
describe User, type: :model do
before :each do
@user = FactoryGirl.create :user
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe User do
describe User, type: :model do
before :each do
@user = FactoryGirl.create :user
@feed = FactoryGirl.create :feed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe User do
describe User, type: :model do
before :each do
@user = FactoryGirl.create :user
@feed = FactoryGirl.create :feed
Expand Down
Loading

0 comments on commit 9f87139

Please sign in to comment.