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

Time execution for pending test file can't be measured due to exception #108

Closed
ArturT opened this issue Apr 15, 2021 · 1 comment
Closed
Labels

Comments

@ArturT
Copy link
Member

ArturT commented Apr 15, 2021

When generating a JSON report for a pending spec file then knapsack gem crashes.

Here is a project we use for development purpose:
https://github.com/KnapsackPro/rails-app-with-knapsack
It has a pending spec file: KnapsackPro/rails-app-with-knapsack@586ce81

$ KNAPSACK_GENERATE_REPORT=true bundle exec rspec spec/pending_spec.rb
Knapsack report generator started!

Pending
  example at ./spec/pending_spec.rb:2 (PENDING: Temporarily skipped with xit)

An error occurred in an `after(:context)` hook.
Failure/Error: raise("test_path needs to be set by Knapsack Adapter's bind method") unless @test_path

RuntimeError:
  test_path needs to be set by Knapsack Adapter's bind method
# /Users/artur/Documents/github/knapsack-pro/knapsack/lib/knapsack/tracker.rb:33:in `test_path'
# /Users/artur/Documents/github/knapsack-pro/knapsack/lib/knapsack/tracker.rb:70:in `update_test_file_time'
# /Users/artur/Documents/github/knapsack-pro/knapsack/lib/knapsack/tracker.rb:28:in `stop_timer'
# /Users/artur/Documents/github/knapsack-pro/knapsack/lib/knapsack/adapters/rspec_adapter.rb:24:in `block (2 levels) in bind_time_tracker'
Knapsack report was generated. Preview:
{
}

Knapsack global time execution for tests: 0.0006259996443986893s

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) Pending
     # Temporarily skipped with xit
     # ./spec/pending_spec.rb:2


Finished in 0.05341 seconds (files took 3.58 seconds to load)
1 example, 0 failures, 1 pending, 1 error occurred outside of examples

The crash happens because the test file path was not set.

      def bind_time_tracker
        ::RSpec.configure do |config|
          config.prepend_before(:context) do
            Knapsack.tracker.start_timer
          end


          config.prepend_before(:each) do
            current_example_group =
              if ::RSpec.respond_to?(:current_example)
                ::RSpec.current_example.metadata[:example_group]
              else
                example.metadata
              end
           
            Knapsack.tracker.test_path = RSpecAdapter.test_path(current_example_group)
          end


          config.append_after(:context) do
            Knapsack.tracker.stop_timer
          end


          config.after(:suite) do
            Knapsack.logger.info(Presenter.global_time)
          end
        end
      end

source: https://github.com/KnapsackPro/knapsack/blob/5eb650a71e5df40fb4157afda3dd265c867a162a/lib/knapsack/adapters/rspec_adapter.rb#L7,L31

Problems

  • Test file path is set Knapsack.tracker.test_path only when at least 1 example was executed in the test file. But for pending test file there are no examples executed so the test path is not set. This leads to exception.

  • If a pending test file is executed after another test file then this can lead to attributing time measured for pending test file to the previously executed test file path.

Related

This bug was introduced after merging PR: #107

@ArturT
Copy link
Member Author

ArturT commented Apr 15, 2021

This is fixed and knapsack 1.21.1 was released.

@ArturT ArturT closed this as completed Apr 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant