Sajid Ali
Sajid Ali

Reputation: 31

Factories {create(:user)} create every time new user in new it block

My code for test case

RSpec.describe "Normal days ", type: :request do
  context 'User ' do
    before(:all) do
      DatabaseCleaner.strategy = DatabaseCleaner::NullStrategy
    end
    let(:user1) { create :user }
    let(:user2) { create :user }
    let(:user3) { create :user }

    it 'Check-In ' do
      check_in(user1)
    end

    it 'Check-Out ' do
      check_out
    end

    it 'get histories ' do
      get_histories
    end
  end
end

Note:

Gem list

gem 'rspec'
gem 'rspec-rails'
gem 'factory_bot_rails', '5.2.0'
gem 'faker', '~> 2.22'
gem 'database_cleaner', '~> 1.5.3'

**Rails verision: **

gem 'rails', '~> 5.2.1'

ruby verision:

ruby '2.6.5'

Actual result

when i run the test case then every case (means when call it class) users (user1,user2,user3) changed.

  1. When run check-in case
user1 = user.email => [email protected] and user.id => 1
user2 = user.email => [email protected] and user.id => 2
user3 = user.email => [email protected] and user.id => 3
  1. When call check-in case call then
user1 = user.email => [email protected] and user.id => 4
user2 = user.email => [email protected] and user.id => 5
user3 = user.email => [email protected] and user.id => 6

Excepted result

after run the all case user value same

  1. When run check-in case
user1 = user.email => [email protected] and user.id => 1
user2 = user.email => [email protected] and user.id => 2
user3 = user.email => [email protected] and user.id => 3
  1. When call check-in case call then

user1 = user.email => [email protected] and user.id => 1
user2 = user.email => [email protected] and user.id => 2
user3 = user.email => [email protected] and user.id => 3

Upvotes: 0

Views: 142

Answers (0)

Related Questions