Skip to content
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

Non-deterministic behaviour for describe and the ` character #1813

Closed
ydakuka opened this issue Feb 16, 2024 · 2 comments
Closed

Non-deterministic behaviour for describe and the ` character #1813

ydakuka opened this issue Feb 16, 2024 · 2 comments

Comments

@ydakuka
Copy link

ydakuka commented Feb 16, 2024

1 case

I have the following spec:

RSpec.describe User do
  subject(:user) { record }

  let(:record) { create(:user) }

  describe `validations` do
    it { is_expected.to allow_values('', nil).for :username }
  end
end

I run tests and I get:

ydakuka@yauhenid:~/Work/main_app$ bin/rails_docker rspec spec/models/user_spec.rb

An error occurred while loading ./spec/models/user_spec.rb.
Failure/Error:
  describe `validations` do
    it { is_expected.to allow_values('', nil).for :username }
  end

Errno::ENOENT:
  No such file or directory - validations
# ./spec/models/user_spec.rb:11:in ``'
# ./spec/models/user_spec.rb:11:in `block in <top (required)>'
# ./spec/models/user_spec.rb:5:in `<top (required)>'

2 case

RSpec.describe User do
  subject(:user) { record }

  let(:record) { create(:user) }

  describe `.custom_search` do
    subject(:result) { described_class.custom_search(query) }

    let(:query) { nil }

    let!(:user) { create(:user, email: email, username: username) }

    let(:email) { Faker::Internet.email }
    let(:username) { Faker::Internet.unique.username(specifier: 5..30, separators: []) }

    context 'when query is blank' do
      let(:query) { '    ' }

      specify do
        expect(result.to_set).to eq Set.new [user]
      end
    end
  end
end

I run tests and get the error again.

ydakuka@yauhenid:~/Work/main_app$ bin/rails_docker rspec spec/models/user_spec.rb

An error occurred while loading ./spec/models/user_spec.rb.
Failure/Error:
    describe `.custom_search` do
      subject(:result) { described_class.custom_search(query) }
  
      let(:query) { nil }
  
      let!(:user) { create(:user, email: email, username: username) }

Errno::ENOENT:
  No such file or directory - .custom_search
# ./spec/models/user_spec.rb:10:in ``'
# ./spec/models/user_spec.rb:10:in `block in <top (required)>'
# ./spec/models/user_spec.rb:5:in `<top (required)>'

3 case

And the last case, I have the following code:

RSpec.describe User do
  subject(:user) { record }

  let(:record) { create(:user) }

  describe `#confirmation_period` do
    subject(:result) { user.confirmation_period }

    let :user do
      create(:user, confirmation_token: confirmation_token,
                    confirmation_sent_at: confirmation_sent_at)
    end

    let(:confirmation_token) { Devise.friendly_token }
    let(:confirmation_sent_at) { Time.zone.yesterday }

    context 'when confirmation_sent_at is nil' do
      let(:confirmation_sent_at) { nil }

      specify do
        expect(result).to be_within(3).of(Time.now.utc)
      end
    end
  end
end

I run tests and get the output:

ydakuka@yauhenid:~/Work/main_app$ bin/rails_docker rspec spec/models/user_spec.rb

Randomized with seed 52396

User
  
    when confirmation_sent_at is nil
      is expected to be within 3 of 2024-02-16 13:31:06.595864359 +0000

Finished in 0.51541 seconds (files took 3.68 seconds to load)
1 example, 0 failures

I expected to see the following output

User
  #confirmation_period
    when confirmation_sent_at is nil
      is expected to be within 3 of 2024-02-16 13:32:56.238174256 +0000

, but the next sentence (#confirmation_period) had disappeared.

@pirj
Copy link
Member

pirj commented Feb 16, 2024

This will be fixed in #1796 ?

@ydakuka
Copy link
Author

ydakuka commented Feb 16, 2024

I hadn't seen this pull request before, but I checked - yes, it fixes my issue.

@ydakuka ydakuka closed this as completed Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants