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

Don't know how to get step code to run #275

Open
calderete opened this issue Nov 20, 2023 · 2 comments
Open

Don't know how to get step code to run #275

calderete opened this issue Nov 20, 2023 · 2 comments

Comments

@calderete
Copy link

calderete commented Nov 20, 2023

I've posted this question twice to the cucumber slack and no response, so asking here now. I was under the impression from the docs that I could use cucumber core to execute and report on tests.

I am trying to use cucumber core to make a test runner that can be executed from ruby code. I'm wanting to use my runner to run tests (with step code) concurrently while being able to fully control behavior and reporting.

My apologies if this is obvious but it appears to me now that the cucumber core api itself does not execute step code and I would like to know (or pointed to some examples/docs of) how to use cucumber core to accomplish the above.

I have made a runner referencing the docs here

My tests have some set to fail expect(1).to eql(2) but when running with my test runner they all are marked as passed and it seems the step code is not run at all.

Here is the output from running my tests

Para cukes are running ✓
Tests will finish ✓
Para runner one is running--PASSED
Para cukes are running ✓
Tests will finish ✓
Para runner two is running--PASSED
Para cukes are running ✓
Tests will fail ✓
Para runner three is running--PASSED
Para cukes are running ✓
Tests will fail ✓
Para runner four is running--PASSED

The steps "Tests will fail" should fail and not be marked as pass (they fail when running with the CLI)

Here is my runner code

class CoreRunner
  include Cucumber::Core
end
# Custom runner class using cucumber API
class ParaRunner
  def run
    scenario = 'features/test/para_runner/para_test_2.feature'
    file_body = File.read(scenario)
    feature = Cucumber::Core::Gherkin::Document.new(scenario, file_body)

    CoreRunner.new.execute([feature], [ActivateSteps.new]) do |events|
      events.on(:test_step_finished) do |event|
        test_step = event.test_step
        result = event.result
        puts "#{test_step.text} #{result}"
      end

      events.on(:test_case_finished) do |event|
        puts "#{event.test_case.name}--#{event.result.to_message.status}"
      end
    end
  end
end

# Activator
class ActivateSteps < Cucumber::Core::Filter.new
  def test_case(test_case)
    test_steps = test_case.test_steps.map do |step|
      activate(step)
    end
    test_case.with_steps(test_steps).describe_to(receiver)
  end

  def activate(step)
    step.with_action {}
  end
end

Thanks for all your help!

@luke-hill
Copy link
Contributor

luke-hill commented Nov 24, 2023

Are you able to get up something runnable ideally in the form of a branch against this repo or a fork that shows the failing test? I'll be able to look at it better that way as I don't have huge amounts of free time now

It looks like your step code "might" be the issue here. But I can't say for certainty as I've not used this area of the codebase much

@calderete
Copy link
Author

calderete commented Dec 14, 2023

Hello @luke-hill and thanks for the suggestion. Sorry for the delayed response, I was on vacation then got sick :(

I have recreated the code I have in my project in a fork of cucumber core here https://github.com/calderete/cucumber-ruby-core

I added a test that can be run with rspec spec/custom_runner_spec.rb because of the nature of the behavior though I cannot get it to fail.

Here is the step code

When('Some cukes are running') do
  $stdout.puts('This step is running')
end

Then('This test will fail') do
  $stdout.puts('This step should fail')
  expect(2).to eql(3)
end

The console does output the scenarios so it seemed to find the scenarios but appears disconnected from the step code in my implementation.

The log outs are not printing and the test gets marked as passed. Because of this I'm not able to make failing test, but it demonstrates that the step code is not being run.

If you could see what I'm doing wrong here I would much appreciate it!

Thanks for all you do!!

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