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

Default example status to unknown if corrupt #2360

Merged
merged 3 commits into from
Mar 27, 2017

Conversation

matrinox
Copy link
Contributor

@matrinox matrinox commented Dec 12, 2016

If the examples.txt is corrupt, it should at least not crash

@myronmarston
Copy link
Member

Can you add a spec for this?

@xaviershay
Copy link
Member

@matrinox are you still interested in this? If not I can have a crack at it.

@xaviershay xaviershay added the Bug label Jan 15, 2017
@matrinox
Copy link
Contributor Author

matrinox commented Jan 16, 2017

@xaviershay go ahead :). Thanks!
@myronmarston Sorry, didn't see this until now

@matrinox
Copy link
Contributor Author

No one has done tests for this so I will take a stab at it

@matrinox
Copy link
Contributor Author

@myronmarston Spec added. Please review

Copy link
Member

@myronmarston myronmarston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good start, @matrinox. I left some feedback.

end
expectation.not_to raise_error
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things...

  1. Since the failure is in last_run_statuses and we already have some specs specifically for that method, I'd prefer this spec was moved to there and re-written to exercise that directly. The specs I'm referring to are here.

  2. Not raising an error is a good thing, but I think we can make the assertion even stronger; specifically that the status is set to UNKNOWN_STATUS. Otherwise, a fix of example.fetch(:status, "BWAH HA HA") could still pass, but the rest of the code in RSpec does not understand that status. So in your re-written spec, please assert that the status is set to UNKNOWN_STATUS.

  3. I think in the other spec file you can get by w/o having to write an external fixture like you did here--instead you can just pass hashes to the simulate_persisted_examples method w/o a :status key. That helps keeps everything necessary to understand the spec visible in one place.

Copy link
Contributor Author

@matrinox matrinox Mar 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Thanks for the feedback. I am not super familiar with the rspec library so I just tried my best to put it where it's already kind of testing it.

  2. is very good for sure. My main concern was just that it didn't crash but I suppose that it should be unknown, not just nil. That might make me change the code some more

  3. Ok thanks! I'll try my best to get that working

@matrinox
Copy link
Contributor Author

Can someone explain to me L107 of spec/rspec/core/configuration/only_failures_support_spec.rb? For context:

          expect(spec_files_with_failures).to(
            be_an(Array) &
            be(spec_files_with_failures) &
            contain_exactly("./spec_1.rb", "./spec_5.rb")
          )

Expect x to be x? Is that a typo?

geoff-lee-lendesk and others added 2 commits March 23, 2017 13:52
-----------------------------------------------------------
On branch master - Mon 12 Dec 2016 10:49:57 PST by matrinox <geoff.lee@lendesk.com>
-----------------------------------------------------------
On branch master - Mon 20 Mar 2017 12:01:23 PDT by matrinox <geofflee25@gmail.com>
@matrinox
Copy link
Contributor Author

I know this isn't related but what's the purpose of 'UNKNOWN_STATUS' beyond defaulting to the old status? If the file itself has an unknown status, then it may not run it despite it potentially being a failure. Especially if it's been corrupted/removed.

My proposal is to set unknown statuses as failure (or treat them as such) when loading from file. Thoughts?

@myronmarston
Copy link
Member

I know this isn't related but what's the purpose of 'UNKNOWN_STATUS' beyond defaulting to the old status?

Are you asking what's the purpose of using UNKNOWN_STATUS as a constant instead of just using a literal 'unknown' string every where? Or why we are using that status at all?

We use a constant because it guards against typos, and saves a bit of memory by re-using the same string instance.

We use this status for examples for which we do not know the status because....what else would se use? If the status is unknown, it makes sense to label it as such. It also allows for filtering from the command line:

rspec --tag last_run_status:unknown

See #2352 for an example of where this is useful.

My proposal is to set unknown statuses as failure (or treat them as such) when loading from file. Thoughts?

I think that's not a good idea because there's no reason to assume examples with an unknown status are failures. For example, maybe the example has never run on this machine before because the repo was just cloned and not all examples ran on the first run (e.g. due to a filter, or due to --fail-fast or whatever). Setting the last_run_status to unknown for all examples for which we do not know the status allows someone to filter to just them from the command line, as I mention above.

Made changes based on @myronmarston feedback
-----------------------------------------------------------
On branch master - Thu 23 Mar 2017 14:46:27 PDT by matrinox <geofflee25@gmail.com>
@myronmarston
Copy link
Member

Expect x to be x? Is that a typo?

It's not a typo. We are using that to require memoization. expect([]).to be([]) fails because while their contents are the same, they are not the same array instance. So that part of the expectation requires that the method returns the same array instance when called a 2nd time, rather than taking the time to re-compute the array from scratch.

@matrinox
Copy link
Contributor Author

It's almost the weekend so I might work on it then but for now, to speed things up a little, do you mind explaining why it's failing only on a jruby configuration? Or how I can easily set it up on my Mac. Thanks

@myronmarston
Copy link
Member

It's almost the weekend so I might work on it then but for now, to speed things up a little, do you mind explaining why it's failing only on a jruby configuration? Or how I can easily set it up on my Mac. Thanks

The bisect cukes randomly fail on JRuby occasionally and we don't know why. Probably a JRuby bug given they pass on MRI 100% of the time. Regardless, I've kicked the JRuby build and we'll see if it goes green. That's how we always deal with it.

@matrinox
Copy link
Contributor Author

@myronmarston looks good now. Welcome feedback

@myronmarston myronmarston merged commit ddd8ff3 into rspec:master Mar 27, 2017
@myronmarston
Copy link
Member

Thanks!

myronmarston added a commit that referenced this pull request Mar 27, 2017
JonRowe pushed a commit that referenced this pull request Apr 20, 2017
* Default example status to unknown if corrupt
-----------------------------------------------------------
On branch master - Mon 12 Dec 2016 10:49:57 PST by matrinox <geoff.lee@lendesk.com>

* Add spec for when examples.txt file are corrupted
-----------------------------------------------------------
On branch master - Mon 20 Mar 2017 12:01:23 PDT by matrinox <geofflee25@gmail.com>

* Default status to UNKNOWN_STATUS if it's valid or nil
Made changes based on @myronmarston feedback
-----------------------------------------------------------
On branch master - Thu 23 Mar 2017 14:46:27 PDT by matrinox <geofflee25@gmail.com>
JonRowe pushed a commit that referenced this pull request Apr 20, 2017
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
* Default example status to unknown if corrupt
-----------------------------------------------------------
On branch master - Mon 12 Dec 2016 10:49:57 PST by matrinox <geoff.lee@lendesk.com>

* Add spec for when examples.txt file are corrupted
-----------------------------------------------------------
On branch master - Mon 20 Mar 2017 12:01:23 PDT by matrinox <geofflee25@gmail.com>

* Default status to UNKNOWN_STATUS if it's valid or nil
Made changes based on @myronmarston feedback
-----------------------------------------------------------
On branch master - Thu 23 Mar 2017 14:46:27 PDT by matrinox <geofflee25@gmail.com>
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
…#2360)

* Default example status to unknown if corrupt
-----------------------------------------------------------
On branch master - Mon 12 Dec 2016 10:49:57 PST by matrinox <geoff.lee@lendesk.com>

* Add spec for when examples.txt file are corrupted
-----------------------------------------------------------
On branch master - Mon 20 Mar 2017 12:01:23 PDT by matrinox <geofflee25@gmail.com>

* Default status to UNKNOWN_STATUS if it's valid or nil
Made changes based on @myronmarston feedback
-----------------------------------------------------------
On branch master - Thu 23 Mar 2017 14:46:27 PDT by matrinox <geofflee25@gmail.com>

---
This commit was imported from rspec/rspec-core@6fdff12.
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants