Giter VIP home page Giter VIP logo

cucumber-ruby-core's Introduction

Cucumber Open - Supported by Smartbear

Cucumber

OpenCollective OpenCollective pull requests issues Test cucumber-core Code Climate

Cucumber is a tool for running automated tests written in plain language. Because they're written in plain language, they can be read by anyone on your team. Because they can be read by anyone, you can use them to help improve communication, collaboration and trust on your team.

Cucumber Gherkin Example

Cucumber Core is the inner hexagon for the Ruby flavour of Cucumber.

It contains the core domain logic to execute Cucumber features. It has no user interface, just a Ruby API. If you're interested in how Cucumber works, or in building other tools that work with Gherkin documents, you've come to the right place.

See CONTRIBUTING.md for info on contributing to Cucumber (issues, PRs, etc.).

Everyone interacting in this codebase and issue tracker is expected to follow the Cucumber code of conduct.

Installation

cucumber-core is a Ruby gem. Install it as you would install any gem: add cucumber-core to your Gemfile:

gem 'cucumber-core'

then install it:

$ bundle

or install the gem directly:

$ gem install cucumber-core

Supported platforms

  • Ruby 3.3
  • Ruby 3.2
  • Ruby 3.1
  • Ruby 3.0
  • Ruby 2.7
  • Ruby 2.6
  • Ruby 2.5
  • JRuby 9.4 (with some limitations)

Usage

The following example aims to illustrate how to use cucumber-core gem and to make sure it is working well within your environment. For more details explanation on what it actually does and how to work with it, see docs/ARCHITECTURE.md.

# cucumber_core_example.rb

require 'cucumber/core'
require 'cucumber/core/filter'

class ActivateSteps < Cucumber::Core::Filter.new
  def test_case(test_case)
    test_steps = test_case.test_steps.map do |step|
      step.with_action { print "processing: " }
    end

    test_case.with_steps(test_steps).describe_to(receiver)
  end
end

feature = Cucumber::Core::Gherkin::Document.new(__FILE__, <<-GHERKIN)
Feature:
  Scenario:
    Given some requirements
    When we do something
    Then it should pass
GHERKIN

class MyRunner
  include Cucumber::Core
end

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

If you run this Ruby script:

ruby cucumber_core_example.rb

You should see the following output:

processing: some requirements ✓
processing: we do something ✓
processing: it should pass ✓

Documentation and support

Copyright

Copyright (c) Cucumber Ltd. and Contributors. See LICENSE for details.

cucumber-ruby-core's People

Contributors

adbatista avatar almostwhitehat avatar aslakhellesoy avatar aurelien-reeves avatar benjis avatar botandrose-machine avatar brasmusson avatar cbliard avatar danascheider avatar dependabot[bot] avatar eduardrudko avatar erran avatar junaruga avatar luke-hill avatar mattwynne avatar mpkorstanje avatar olleolleolle avatar orend avatar orien avatar os97673 avatar renovate[bot] avatar richarda avatar timotheeville avatar tom025 avatar tooky avatar twalpole avatar utkarsh2102 avatar vincent-psarga avatar vincentcapicotto avatar xtrasimplicity avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cucumber-ruby-core's Issues

Rake task exiting with 0 on failure

The build is failing on JRuby, but passing on the other Rubies despite having two failing specs.

It seems that the rake task exits with 0 even when there are scenarios failing. @tooky can you take a look at this?

Strip out Table

The Table class we brought over from Cucmber 1.0 has too many responsibilities, many of which don't belong in the core. We should pare it right down to the bare minimum we need, then add features back in as we find they're needed.

Support for pending steps and scenarios

Currently there is no support for pending steps.

Currently what happens in cucumber when a step of the form

Given(/^pending$/) { pending }

is executed it raises a Cucumber::Pending error. In the test runners for cucumber-core this error is not rescued and so pending steps and scenarios are not reported. It also skips After hooks.

I think we need to move Cucumber::Pending to core and change the test runners to handle pending steps.

scenario outline error reporting in Before hook

Hello,

I see a difference between running a Scenario outline and a Scenario. If I run a scenario and error is raised in Before hook, then scenario is marked as failed and steps are skipped.

With a Scenario outline though, the steps are executed but at the end scenario is marked as failing. No backtrace is printed out. This can be rather confusing.

Allow reports to register for Runner events

Right now the Reports just implement an API made of these methods:

before_test_case
before_test_step
after_test_step
after_test_case

@tooky and I have decided this should be whittled down to a single method, register_runtime_events passing in a class that can collect blocks to be called back on the report. This gives the reports more control about which events they're interested in, so that the runner doesn't need to waste time calling events that the reports don't care about.

Background.feature is always nil

As @e2 noted (cucumber/gherkin#334), the ast class for Background has an attr_accessor for :feature, but since the #feature is never set on the background object, #feature is always nil. Therefore things like background.feature.name in for instance #before_background in formatter will not work.

Build an ExecutionTree similar to what's coming in Gherkin3.

As described in cucumber-attic/gherkin#6, Gherkin3 will provide an Execution Tree (ET) which is intended to make it simpler for Cucumber to execute and report results.

Since Gherkin3 is several months from being useable it makes sends that this project uses Gherkin2 to build an ET similar to what Gherkin3 will do in the future.

I think it would be great if the temporary builder/compiler/AST/ET lives in a separate module that can be easily swapped out when Gherkin3 is ready.

I created this ticket primarily for discussion to make sure everyone understands the plan. Please weigh in with questions and comments.

Use Status classes during Test::Case execution

Right now we use the result classes, but saying that a Test::Case is Passed when it hasn't finished running is inaccurate. We can use the Result classes to store the result, but we should have an intermediate set of Status classes (something like Unknown, Passing, Failed, Passed) that we use during execution, then only talk about a Result when we've finished.

Thanks to @aslakhellesoy for this suggestion.

Move mapper out into front-end

Since the mapper is just a special case filter anyway, maybe we don't need to have it here. If we leave it in the core, it will just become harder to change as other people will build things around it.

I wonder if this would help resolve my issues with it having an awkward API.

@tooky WDYT?

Raise a `TagExcess` before executing test suite

As pointed out by @pdswan.

The current version of cucumber raises a TagExcess before executing the test suite. Cucumber core will only raise a TagExcess after it has executed the test suite.

This issue needs to be addressed for cucumber 2.0 to be compatible with the current version of cucumber.

Allow for AND tag expressions

This might be needed as an interim step before #20 is implemented. In implementing #13, I realised why the current Cucumber passes an array of tag expressions to Gherkin::TagExpression. It's because Cucumber's CLI currently uses multiple expressions to communicate AND logic.

Unfortunately (for both Test::Case.match_tags? and for the filter: option on Core#compile and Core#execute) I chose to accept only a single expression.

This won't integrate with the current front-end until we can pass multiple expressions.

Test case names for Scenario Outlines contains the non-localized word "row"

The name of a test case for an example scenario from an Scenario Outline is composed as:

"<outline name>, <example table name> (row <number>)"

The word "row" is hard-coded in English (in case.rb). "Row" will look a bit odd when using a language other the English in the feature file (especially when using a language not using the Latin alphabet).

Would it be better to use "#" instead of "row", to make the row designation more language neutral?

"<outline name>, <example table name> (#<number>)"

How do I use the reporting API in real life?

Issue: I'm updating a gem that reports on scenario success/fail plus scenario source to an external reporting tool via a REST api. It doesn't work in Cucumber 2.0 so I'm trying to learn how to do it in the Cuke 2.0 world and can't find enough documentation to get started.

I've read through the example of using a reporting class and getting it to work but I'm mystified by two things;-

  1. How do I plug in a reporting class into real world Cucumber? I can't believe I'd have to write my own runner and plug the reporting class into that. How do I register my reporting class with real world Cucumber in the features/support/env.rb file ?
  2. Having an api to send messages to a report class that responds to certain methods is cool, but Cucumber::Formatter::Html does loads more. Does Cucumber::Formatter::Html behave as a report class, or is it a special case that has a different api?

Is there any documentation or online email conversation I can be pointed to so I can learn how to catch the messages that happen as Cucumber runs and then send information to an external reporting tool?

Thanks

John Small

Allow for Around hooks

Still need to decide the best way to do this, but the Test::SuiteRunner is going to need to yield to the hooks as it runs each Test::Case so that we can allow for Around hooks.

Pass in URI/path with Gherkin doc

Right now there's no way to pass in the path of a file when you parse it (we just default it to UNKNOWN), which means the location on the AST isn't useful when you want to print it (e.g. to show where a failed scenario is located).

We should change the way the Core#parse method works so you can (or have to) pass in a path with the gherkin doc.

After hooks should never be skipped (except in dry run mode)

I'm investigating why the wire protocol scenarios on the front-end are leaving wire servers lying around. The reason is that when the scenario fails, the after hook that cleans up and kills the wire server isn't being run.

We need to change the logic here. I think it may be as simple as changing the behaviour of HookStep#skip to still execute.

Possible bug with DataTable from multi-line argument parsing.

I noticed this from the work I was doing to get the html formatter from cucumber working.

The Line number for a Ast::DataTable::Cells instance is thrown away after parsing a DataTable.

Consider this code:

# lib/cucumber/core/ast/multiline_argument.rb
def from(argument)
  #...

  case(rubify(argument))
  when String
    #...
  when Array
    Ast::DataTable.new(argument.map{|row| row.cells})
  else
    #...
  end
end

In the Array case the argument looks like this...

[<Gherkin::Formatter::Model::DataTableRow:... @comments=[], @cells=["name", "surname"], @line=5>,
<Gherkin::Formatter::Model::DataTableRow:... @comments=[], @cells=["rob", "westgeest"], @line=6>]

So when the below is done...

argument.map{|row| row.cells} #=> [["name", "surname"], ["rob", "westgeest"]] 

the line numbers are lost.

Ast::DataTable copes with this by rescuing and returning -1 when creating it's cell matrix on initialization.

#lib/cucumber/core/ast/data_table.rb:260
def create_cell_matrix(raw) #:nodoc:
  @cell_matrix = raw.map do |raw_row|
    line = raw_row.line rescue -1
    raw_row.map do |raw_cell|
      new_cell(raw_cell, line)
    end
  end
end

This impacts the dom ids that the cucumber html formatter produces for datatable rows... i.e. all of them will be #row_-1.

This looks like a bug. Does this need to be addressed?

Make DataTable immutable

It was a bad design decision to make tables mutable, and it has caused many bugs. I suggest that in the rewrite, mutators are only added for backwards compatibility, and that they issue a BIG warning that non-mutating methods should be used instead (returning a new table).

Handle undefined steps properly

If we run in --dry-run mode, we should report all undefined steps.

Even if a step is skipped, we should report its undefined-ness.

Transform steps should also apply to Data Table elements

Steps arguments are not created equal.
For instance, 'normal' step arguments that are created as capturing group
in the regular expression of a StepDefinition can be subjected to a Transform step.
Oddly enough, step arguments that come from an AST::Table cannot be Transformed.
This is annoying when, like my team mates, Transforms are used to do text substitutions
and the expectations are that the substitutions are performed for every step data value.
As a workaround to that weird limitation, I wrote long time ago a method for the World object that
invoked the Transform upon the AST::Table elements.

This worked fine until recently we got the warning:
[warning] map_column! will be deprecated

Then I realize that the idea of making Data Table immutable will only break the workaround
but will make the Transform steps completely ineffective for AST::Table.

What one needs is an implementation that follows the Principle of Least Surprise:
-One should be able to perform the same operations/transformations on step arguments
regardless the syntax used to create them (i.e. via a regexp capturing group, a multiline text or a data table).

Remove dead code from lib/cucumber/core/ast

This code was copied and pasted in from Cucumber 1.x's master branch and contains a lot of code that we don't need anymore. The #accept methods can all go, anything to do with handling results can go. Those classes can be immutable now.

Use bool for tag expressions

See discussion in #13.

This will require a translation layer (we can put this in the front-end) to translate between bool's expressions and the ones used in Cucumber.

Fail build on warnings

The tests generate a ton of warnings right now. We should make the build fail if there are warnings - and get rid of them.

Rename `Mapping` to `Action`

I'm finding it confusing with these terms like Mapper and Mapping. I think that the verb map is appropriate, but I don't like the name Mapping for the thing that results. I think Action is a better name:

A step is mapped to an action

I'd like to rename Cucumber::Core::Test::Mapping to Action

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.