Don't know how to get step code to run

Aperta
#275 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@luke-hill ci sta già lavorando.

Dal 31/3/2025.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

:bug: bug

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!

Lingua principale
Ruby
Stelle
36
Fork
48
Merge medio
1h 54m
PR unite (30g)
4

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cucumber/cucumber-ruby-core

Tutte le issue di cucumber/cucumber-ruby-core

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.