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

Could not get expect nil to work #5

Open
kwokster10 opened this issue Mar 14, 2016 · 2 comments
Open

Could not get expect nil to work #5

kwokster10 opened this issue Mar 14, 2016 · 2 comments

Comments

@kwokster10
Copy link

I tried this in a controller spec:

let(:model) { FactoryGirl.create(:model) }

it 'association does not equal nil' do
     post :add_assocation, { <necessary_params> }
     expect{ model.reload.association }.to eventually_not eq nil
end

Also tried:

 expect{ model.association }.to eventually_not eq nil
 expect{ model.reload.association }.to_not eventually eq nil
 expect{ model.reload.association }.to eventually_not(eq nil)
 expect{ model.reload.association }.to eventually_not(eq nil).within 5

here's the error message:

After 46 tries, the last failure message was:

       expected: nil
            got: nil

       (compared using ==)

Model and association have a one to one relationship.

Any advice would be appreciated.
Thanks.

@hawknewton
Copy link
Owner

Try replacing model.reload.association above with nil and run the specs as I am unable to recreate the issue.

You also may want to try the be_nil matcher. You could be getting a value that serializes to the string nil.

@kwokster10
Copy link
Author

I have used the be_nil matcher as well. If I replace model.reload.association with nil, then I would be testing nil to eventually equal nil, which works but I want to check that model.reload.association is equal to nil.

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