Conversation
|
@tom93 keen to know if you any objections to this idea, before I continue through and do the rest of the tests :) |
|
I'm not that familiar with rspec, but having the second test run be independent sounds like a pretty good idea! Small clarifications:
Do you mean generate these fixtures/models?
I'm a little confused, it seems like this PR is removing uses of before(:each). |
Do you mean that before(:all) is bad, and let/before(:each) are good? (I see that a bare "before" is the same as before(:each), and "let" seems like a lazy version of before(:each) so basically interchangeable.) |
Yeah, I think that's the intention (was discussed briefly on Discord: https://discord.com/channels/670126531489824788/678154623571329025/1363084851737137272) |
|
Yes, clearly I needed to read my commit message better. let(:x) is a preferred mechanism to assigning an ivar in a before block, (https://www.betterspecs.org/#let). One big reason its better is that it has much clearer / more obvious declarations, especially when you use nested contexts. Yes,
Yes, this was supposed to read models. Will update soon. |
648cb02 to
4672e9e
Compare
|
I have updated the commit message, but I haven't copied it back into the GH PR description yet. |
4672e9e to
f5a4b49
Compare
f5a4b49 to
1875470
Compare
This stack of pull requests is managed by Graphite. Learn more about stacking. |
1875470 to
4ce2ff0
Compare
4ce2ff0 to
8a3725d
Compare
ea518a6 to
2a598e6
Compare
f4e1438 to
41073c0
Compare
2a598e6 to
8a3e0ff
Compare
41073c0 to
f6ff75b
Compare
f6ff75b to
9078bba
Compare
Having this helper generate these records before the test suite runs means they are not included any the standard rspec transactional tests mechanism. This means that if the suite cannot fully complete for any reason, such as a syntax error, or if the number of create/destroy is not perfectly matched in a test then the following test run will fail. Using let(:x) and before is best practise, and shouldn't have a significant effect on test runtimes.
9078bba to
b48f347
Compare
Holmes98
left a comment
There was a problem hiding this comment.
This is around 10 seconds slower for me (23s vs 13s), but I'm okay with that.
Huh I might get you to run a profiler at some point as I don't get that change - its within 1s and within the stddev for me. |
|
It's also around 10s slower in CI (in the rspec step): |
|
Hmm you are right - I will dig into that later. I don't think its a blocker, and I am sure I can make it faster again. |
|
Yeah I'm fine with just merging this for now. |
|
I'd like to take a look!
|
|
I think all the new time is spent hashing passwords, which should be
should be possible to fix (using caching). I'll look into it.
|
|
Thanks Tom, appreciate you! It could be as simple as we hard-code a passwordhash rather than re-hashing, which I think is a relatively common solution. |
|
Unfortunately Devise's "password=" method (in
lib/devise/models/database_authenticatable.rb) unconditionally recomputes
the hash (even if we manually set the encrypted_password attribute). This
<https://blog.plataformatec.com.br/2011/12/three-tips-to-improve-the-performance-of-your-test-suite/>
suggests setting "Devise.stretches = 1" in the spec helper, other ideas
welcome!
|
|
Nice, can confirm that setting Could maybe set that conditionally in the initializer instead of spec_helper, since that's what the Devise currently does in the template: But either way works. |

Having this helper generate these tests in before the individual test
runs means they are not included any the standard rspec transactional
tests mechanism. This means that if the suite cannot fully complete for
any reason, such as a syntax error, or if the number of create/destroy
is not perfectly matched in a test then the following test run will
fail.
Using let(:x) and before(:each) is best practise, and shouldn't have a
significant effect on test runtimes.