Skip to content

Replace FactoryGirl with FactoryBot everywhere #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Use this gem to set up a testing framework. The gem modifies a Rails application
* "RSpec Rails":https://github.com/rspec/rspec-rails – installs RSpec gems with support for Rails
* "Capybara":https://github.com/jnicklas/capybara – tests web pages
* "Database Cleaner":https://github.com/bmabey/database_cleaner – a clean slate for databases
* "FactoryGirl Rails":https://github.com/thoughtbot/factory_girl_rails – creates test data
* "FactoryBot Rails":https://github.com/thoughtbot/factory_bot – creates test data
* "Launchy":https://github.com/copiousfreetime/launchy – view errors in your web browser
* "Selenium Webdriver":http://docs.seleniumhq.org/projects/webdriver/ – for tests that require JavaScript

Expand Down Expand Up @@ -47,7 +47,7 @@ group :development do
end
group :development, :test do
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'factory_bot'
end
group :test do
gem 'capybara'
Expand Down Expand Up @@ -128,7 +128,7 @@ config.generators do |g|
routing_specs: false,
controller_specs: false,
request_specs: false
g.fixture_replacement :factory_girl, dir: "spec/factories"
g.fixture_replacement :factory_bot, dir: "spec/factories"
end
</pre>

Expand Down Expand Up @@ -174,13 +174,13 @@ It will also modify *spec/rails_helper.rb*:
config.use_transactional_fixtures = false
</pre>

h3. FactoryGirl Configuration
h3. FactoryBot Configuration

The generator will set up FactoryGirl shortcuts with a file *spec/support/factory_girl.rb*:
The generator will set up FactoryBot shortcuts with a file *spec/support/factory_bot.rb*:

<pre>
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.include FactoryBot::Syntax::Methods
end
</pre>

Expand Down
2 changes: 1 addition & 1 deletion lib/generators/testing/configure/configure_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def configure_framework
gsub_file 'spec/rails_helper.rb', /config.use_transactional_fixtures = true/, "config.use_transactional_fixtures = false"
gsub_file 'spec/rails_helper.rb', /# Dir/, "Dir"
copy_file 'database_cleaner.rb', 'spec/support/database_cleaner.rb'
copy_file 'factory_girl.rb', 'spec/support/factory_girl.rb'
copy_file 'factory_bot.rb', 'spec/support/factory_bot.rb'
when 'devise'
copy_file 'spec/devise/support/devise.rb', 'spec/support/devise.rb'
copy_file 'spec/devise/support/helpers/session_helpers.rb', 'spec/support/helpers/session_helpers.rb'
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/testing/configure/templates/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
routing_specs: false,
controller_specs: false,
request_specs: false
g.fixture_replacement :factory_girl, dir: "spec/factories"
g.fixture_replacement :factory_bot, dir: "spec/factories"
end
2 changes: 1 addition & 1 deletion lib/generators/testing/configure/templates/factory_girl.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.include FactoryBot::Syntax::Methods
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :user do
name "Test User"
email "[email protected]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# When I sign in with valid credentials
# Then I see a success message
scenario 'user can sign in with valid credentials' do
user = FactoryGirl.create(:user)
user = FactoryBot.create(:user)
signin(user.email, user.password)
expect(page).to have_content I18n.t 'devise.sessions.signed_in'
end
Expand All @@ -30,7 +30,7 @@
# When I sign in with a wrong email
# Then I see an invalid email message
scenario 'user cannot sign in with wrong email' do
user = FactoryGirl.create(:user)
user = FactoryBot.create(:user)
signin('[email protected]', user.password)
expect(page).to have_content I18n.t 'devise.failure.not_found_in_database', authentication_keys: 'email'
end
Expand All @@ -41,7 +41,7 @@
# When I sign in with a wrong password
# Then I see an invalid password message
scenario 'user cannot sign in with wrong password' do
user = FactoryGirl.create(:user)
user = FactoryBot.create(:user)
signin(user.email, 'invalidpass')
expect(page).to have_content I18n.t 'devise.failure.invalid', authentication_keys: 'email'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# When I sign out
# Then I see a signed out message
scenario 'user signs out successfully' do
user = FactoryGirl.create(:user)
user = FactoryBot.create(:user)
signin(user.email, user.password)
expect(page).to have_content I18n.t 'devise.sessions.signed_in'
click_link 'Sign out'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# Then I should see an account deleted message
scenario 'user can delete own account' do
skip 'skip a slow test'
user = FactoryGirl.create(:user)
user = FactoryBot.create(:user)
login_as(user, :scope => :user)
visit edit_user_registration_path(user)
click_button 'Cancel my account'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# When I change my email address
# Then I see an account updated message
scenario 'user changes email address' do
user = FactoryGirl.create(:user)
user = FactoryBot.create(:user)
login_as(user, :scope => :user)
visit edit_user_registration_path(user)
fill_in 'Email', :with => '[email protected]'
Expand All @@ -31,8 +31,8 @@
# When I try to edit another user's profile
# Then I see my own 'edit profile' page
scenario "user cannot cannot edit another user's profile", :me do
me = FactoryGirl.create(:user)
other = FactoryGirl.create(:user, email: '[email protected]')
me = FactoryBot.create(:user)
other = FactoryBot.create(:user, email: '[email protected]')
login_as(me, :scope => :user)
visit edit_user_registration_path(other)
expect(page).to have_content 'Edit User'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# When I visit the user index page
# Then I see my own email address
scenario 'user sees own email address' do
user = FactoryGirl.create(:user)
user = FactoryBot.create(:user)
login_as(user, scope: :user)
visit users_path
expect(page).to have_content user.email
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# When I visit the user profile page
# Then I see my own email address
scenario 'user sees own profile' do
user = FactoryGirl.create(:user)
user = FactoryBot.create(:user)
login_as(user, :scope => :user)
visit user_path(user)
expect(page).to have_content 'User'
Expand All @@ -28,8 +28,8 @@
# When I visit another user's profile
# Then I see an 'access denied' message
scenario "user cannot see another user's profile" do
me = FactoryGirl.create(:user)
other = FactoryGirl.create(:user, email: '[email protected]')
me = FactoryBot.create(:user)
other = FactoryBot.create(:user, email: '[email protected]')
login_as(me, :scope => :user)
Capybara.current_session.driver.header 'Referer', root_path
visit user_path(other)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :user do
name "Test User"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe User do

before(:each) { @user = FactoryGirl.create(:user) }
before(:each) { @user = FactoryBot.create(:user) }

subject { @user }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :user do
name "Test User"
email "[email protected]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# When I visit the user index page
# Then I see my own email address
scenario 'user sees own email address' do
user = FactoryGirl.create(:user, :admin)
user = FactoryBot.create(:user, :admin)
login_as(user, scope: :user)
visit users_path
expect(page).to have_content user.email
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
describe UserPolicy do
subject { UserPolicy }

let (:current_user) { FactoryGirl.build_stubbed :user }
let (:other_user) { FactoryGirl.build_stubbed :user }
let (:admin) { FactoryGirl.build_stubbed :user, :admin }
let (:current_user) { FactoryBot.build_stubbed :user }
let (:other_user) { FactoryBot.build_stubbed :user }
let (:admin) { FactoryBot.build_stubbed :user, :admin }

permissions :index? do
it "denies access if not an admin" do
Expand Down