Giter VIP home page Giter VIP logo

cucumberl's Introduction

cucumberl

A pure-erlang, open-source, implementation of Cucumber (http://cukes.info). This provides a subset of the Cucumber feature definition language.

Quick Start

You'll need erlang, of course.

To do a build, do...

./rebar3 compile

To run unit tests, do...

./rebar3 eunit

There's are sample feature files (examples/complex_sample/features and examples/complex_sample/features) and step definitions (in examples/src). Running make test will execute these too.

You can also run them by hand, for example...

examples $ ../cucumberl
Feature: Addition                                                :1
  In order to avoid silly mistakes                               :2
  As a math idiot                                                :3
  I want to be told the sum of two numbers                       :4
                                                                 :5
  Scenario: Add two numbers                                      :6
    Given I have entered 50 into the calculator                  :7
    And I have entered 70 into the calculator                    :8
    When I press add                                             :9
    Then the result should be 120 on the screen                  :10   ok
                                                                 :11

etc.....

Slow Start

So you want to write your own step definitions? No problem. Any erlang module that implements step definitions should export a step/2 function, with this kind of call signature...

Action(TokenList, State, Info)

Where Action is:

  • given
  • 'when'
  • then

The TokenList parameter is a list of either atoms or strings, such as...

[i, have, entered, "Joe Armstrong", into, the, authors, field]

So for example, the previous TokenList would also be accepted in a function definition like this:

given([i, have, entered, Name, into, the, authors, field], State, _) ->
    {ok, NewState}.

The State parameter is the state the last step function returned in the state field of the tuple. In the above example, this is NewState.

The Info parameter is a tuple of helpful debug information, such as the {LineText, LineNum}, of what cucumberl is currently processing. The Info parameter is usually ignored unless you're deep into debugging your scenario/steps.

Here's how you'd write a few step definition functions, using erlang's pattern matching.

given([i, have, entered, N, into, the, calculator], _State, _Info) ->
  % Your step implementation here.
  todo.

'when'([, i, press, add], _, _) ->
  % Your step implementation here.
  todo.

then([the, result, should, be, Result, on, the, screen], _, _) ->
  % Your step implementation here.
  todo.

Notice that all the tokens have been atomized (and turned lowercase).

  • The atoms true and ok in the state tuple represent success and print ok on the console
  • A two-tuple of the form {failed, Reason} indicates failure

The above step definitions will match a scenario like the following...

Scenario: Add two numbers
  Given I have entered 50 into the calculator
  And I have entered 70 into the calculator
  When I press add
  Then the result should be 120 on the screen

Running cucumberl

Running cucumberl on the command line is very simple. Just execute the cucumberl self-contained escript.

To run a feature file through cucumberl using the erlang API...

cucumberl:run(PathToFeatureFile).

For example...

cucumberl:run("./features/sample.feature").

or

cucumberl:run("./features/sample.feature", FeatureDefinitionModule).

The FeatureDefinitionModule parameter is an optional module that implements the feature and contains the step callbacks. However, it is only needed when the name of the step implementation is different then the name of the feature. For example...

cucumberl:run("./features/auction.feature",
               auction).

is exactly equivalent to

cucumberl:run("./features/auction.feature").

However, you may want to implement the feature in a different module, such as ...

cucumberl:run("./features/auction.feature", some_other_module).

perfectly acceptable but not recommended.

Scenario Outlines

There's basic support for Scenario Outlines, aka Example Tables, in cucumberl. However, placeholders names should be all lowercase, and there shouldn't be any blank lines before the "Examples:" label. For example...

Scenario Outline:
  Given I have cleared the calculator
  And I have entered <a> into the calculator
  And I have entered <b> into the calculator
  When I press <op>
  Then the result should be <ab> on the screen
  Examples:
    |  a | b | ab | op       |
    |  1 | 1 | 2  | add      |
    |  1 | 3 | 3  | multiply |
    |  2 | 3 | 6  | multiply |
    | 10 | 1 | 11 | add      |

See the files examples/simple_sample/src/simple_sample_table.erl and examples/simple_sample/features/simple_sample_table.feature for more details.

License

MIT - We made this for you!

Feedback, or getting in touch

Improvements and patches welcomed -- [email protected]

Cheers, Steve Yen

cucumberl's People

Contributors

ericbmerritt avatar hyperthunk avatar steveyen 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  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

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

cucumberl's Issues

please add a new git tag

Also, it seems this very useful library has been abandoned. I'd be willing to pick it up as a maintainer if you're interested.

Does not detect errors in steps

This is a great, except....
I modified the example sample.feature to be...

Then the result should be 123 on the screen

and it still passed...

erl -pa ebin -noshell -s sample main -s init stop
Feature: Addition                                                :1
  In order to avoid silly mistakes                               :2
  As a math idiot                                                :3
  I want to be told the sum of two numbers                       :4
                                                                 :5
  Scenario: Add two numbers                                      :6
    Given I have entered 50 into the calculator                  :7    ok
    And I have entered 70 into the calculator                    :8    ok
    When I press add                                             :9    ok
    Then the result should be 123 on the screen                  :10   ok
                                                                 :11

1 scenarios
4 steps

trying to run sample files on Ubuntu, getting errors!

Hope someone sees this, I really can't get any info on this anywhere else and I'm kind of a beginner to this and I can't google out of my problems no more, so.

I'm experiencing some issues when I attempt to run sample files on the console, here's what I get:

jim@ubuntu:~/Dokument/Cucumberl/cucumberl-master$ sudo make
./rebar compile escriptize
make: execvp: ./rebar: Permission denied
make: *** [build] Error 127

jim@ubuntu:~/Dokument/cucumberl-master/examples/failures$ sudo make
../../rebar clean compile eunit
==> failures (clean)
==> failures (compile)
Compiled src/fail.erl
ERROR: git describe --always --tags failed with error: 127
make: *** [test] Error 1

I'm not entirely sure if I'm doing this right, if someone can help me troubleshoot the issue it would help me a lot to get on with my project tasks!

Thanks for any help! //c

given an 'and' clause cucumberl does not report the correct step definition

Lets say you have a and clause for a then statement. Something like

Then ...
and build the project normally

that you do not implement. Cumberl will reprot the following

a step definition snippet...
step(['and',build,the,project,normally], _) ->
  undefined.

When it should actually report

a step definition snippet...
step([then,'and',build,the,project,normally], _) ->
  undefined.

Version tags

Could you maybe provide a git tag on the tip of the repo named 'v0.0.5' or something like that? (And, of course, add new tags when new version bumps occur?)

Consider deprecating multiple step modules

The use of multiple step modules for a single feature (file) seems a little haphazard. It's intent appears to be sharing of code (i.e., step function definitions) between modules, but I think there are other, cleaner ways to do this.

The use of helper modules, for example, would alleviate the need for this, and is supported on the cli (see https://github.com/hyperthunk/cucumberl/blob/master/src/cucumberl_cli.erl#L45) and could easily be moved into the main cucumber module.

Also, not processing multiple step modules would simplify error handling and negate the requirement to always implement a stub function clause in your modules, i.e.,

%% no more of these!!!
step(_, _) -> undefined.

Please let me know if you would consider this change, as I'd be happy to contribute.

Problems in a fresh install

Hi,

I've just cloned your repo I found several problems while trying to use it. I describe them below:

  1. It seems like you changed the layout of the examples/ dir but didn't update your rebar.config's sub_dirs option to reflect the change. As a result, if you run "make test" no features are executed.
  2. Running ../cucumberl inside of examples/ dir doesn't run any feature. You have to cd into each sample and run ../../cucumberl

3.There are some bugs in the cucumberl_parser:process_line function that break the execution of the features.

If you wish I can send a patch with the fix to those bugs in cucumberl_parser.

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.