Setup Faker and Factorybot
This commit is contained in:
7
spec/factories/users.rb
Normal file
7
spec/factories/users.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
username { Faker::Internet.username }
|
||||
email_address { Faker::Internet.email }
|
||||
password { Faker::Internet.password(min_length: 12, max_length: 18) }
|
||||
end
|
||||
end
|
20
spec/features/contest_spec.rb
Normal file
20
spec/features/contest_spec.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.feature "Contests", type: :feature do
|
||||
context "visiting the home page" do
|
||||
let!(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
visit '/'
|
||||
fill_in "Email address", with: user.email_address
|
||||
fill_in "Password", with: user.password
|
||||
click_button "Sign in"
|
||||
end
|
||||
|
||||
it "should display the username" do
|
||||
visit root_path
|
||||
|
||||
expect(page).to have_content(user.username)
|
||||
end
|
||||
end
|
||||
end
|
@@ -23,7 +23,7 @@ require 'rspec/rails'
|
||||
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
||||
# require only the support files necessary.
|
||||
#
|
||||
# Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }
|
||||
Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }
|
||||
|
||||
# Checks for pending migrations and applies them before tests are run.
|
||||
# If you are not using ActiveRecord, you can remove these lines.
|
||||
|
5
spec/support/factory_bot.rb
Normal file
5
spec/support/factory_bot.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
require "factory_bot_rails"
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include FactoryBot::Syntax::Methods
|
||||
end
|
Reference in New Issue
Block a user