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

Track time in before and after :context #107

Merged
merged 1 commit into from
Apr 15, 2021

Conversation

caalberts
Copy link
Contributor

@caalberts caalberts commented Apr 15, 2021

This PR changes the start and end of the timer to be done in prepend_before(:context) and append_after(:context) so that the time tracked by Knapsack includes time spent in before(:context) and after(:context).

Closes #106

Given a spec file as follows:

RSpec.describe 'Foo' do
  context 'when something' do
    before(:context) do
      sleep(5)
    end

    before do
      sleep(0.1)
    end

    it 'test_1' do
      sleep(0.2)
      expect(true).to be_truthy
    end

    it 'test_2' do
      sleep(0.3)
      expect(true).to be_truthy
    end
  end
end
Finished in 5.72 seconds (files took 0.74649 seconds to load)
2 examples, 0 failures

The test takes a total of 5.7 seconds (5 + 2*0.1 + 0.2 + 0.3), as recorded by RSpec. Knapsack should also track this file as 5.7 seconds.

@caalberts
Copy link
Contributor Author

@ArturT Could you review please?

expect(tracker).to receive(:start_timer)

expect(tracker).to receive(:stop_timer)
expect(tracker).to receive(:start_timer).ordered
Copy link
Member

Choose a reason for hiding this comment

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

Nice improvement with ordered. I did not know about it
https://relishapp.com/rspec/rspec-mocks/docs/setting-constraints/message-order

ArturT added a commit to KnapsackPro/rails-app-with-knapsack that referenced this pull request Apr 15, 2021
@ArturT ArturT merged commit 1a059f7 into KnapsackPro:master Apr 15, 2021
@ArturT
Copy link
Member

ArturT commented Apr 15, 2021

@caalberts Thank you for the PR. I've released a new version of knapsack 1.21.0.

@ArturT
Copy link
Member

ArturT commented Apr 15, 2021

Note

context hooks seems to be introduced in RSpec 3.0
https://relishapp.com/rspec/rspec-core/v/3-0/docs/hooks/before-and-after-hooks

There is no info about context in RSpec 2.99
https://relishapp.com/rspec/rspec-core/v/2-99/docs/hooks/before-and-after-hooks

Just info for myself that this change might not work for legacy RSpec 2.x. But that's fine. RSpec 2.x was released last time in 2014 (long time ago).
https://github.com/rspec/rspec-core/blob/main/Changelog.md#2992--2014-08-19

@ArturT
Copy link
Member

ArturT commented Apr 15, 2021

This PR introduced a new bug #108

I'm working on solving that.

@ArturT
Copy link
Member

ArturT commented Apr 15, 2021

It's fixed and knapsack 1.21.1 has been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Knapsack::Adapters::RSpecAdapter does not track time spent in before or after :context
2 participants