├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── Makefile ├── README.md ├── bin └── cucumber-lua ├── cucumber-lua-0.0-2.rockspec ├── examples └── calculator │ ├── calculator.lua │ └── features │ ├── addition.feature │ └── step_definitions │ ├── cucumber-lua.wire │ └── steps.lua ├── features ├── cucumber_lua.feature ├── step_definitions │ └── cucumber_lua_steps.rb ├── support │ └── env.rb └── wire_server.feature ├── renovate.json ├── server.lua ├── spec ├── cucumber_spec.lua ├── dsl.lua ├── inspect.lua └── runner.lua └── src └── cucumber.lua /.gitignore: -------------------------------------------------------------------------------- 1 | tmp -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | sudo: false 3 | 4 | env: 5 | - LUA="lua 5.2" 6 | - LUA="lua 5.3" 7 | - LUA="luajit 2.0" 8 | - LUA="luajit 2.1" 9 | 10 | before_install: 11 | - pip install hererocks 12 | - hererocks env --$LUA -rlatest # Use latest LuaRocks, install into 'env' directory. 13 | - source env/bin/activate # Add directory with all installed binaries to PATH. 14 | - luarocks install busted # We don't use busted, but it installs all of our dependencies. This should be tidied up when someone gets a chance. 15 | 16 | install: 17 | - luarocks make 18 | 19 | script: 20 | - lua spec/runner.lua 21 | 22 | matrix: 23 | allow_failures: 24 | - env: LUA="lua 5.3" 25 | - env: LUA="luajit 2.0" 26 | - env: LUA="luajit 2.1" -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGE LOG 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | This project adheres to [Semantic Versioning](http://semver.org). 6 | 7 | This document is formatted according to the principles of [Keep A CHANGELOG](http://keepachangelog.com). 8 | 9 | Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md) for more info on how to contribute to Cucumber. 10 | 11 | ---- 12 | 13 | ## [Unreleased] - In Git 14 | 15 | ### Removed 16 | 17 | ### Added 18 | 19 | * Added this CHANGELOG.md file per [cucumber/cucumber #251](https://github.com/cucumber/cucumber/issues/251) ([#6](https://github.com/cucumber/cucumber-lua/pull/6) [jaysonesmith](https://github.com/jaysonesmith)) 20 | * Feature/end scenario hook [#3](https://github.com/cucumber/cucumber-lua/pull/3) 21 | 22 | ### Changed 23 | 24 | ### Fixed 25 | 26 | 27 | 28 | 29 | [britzl]: https://github.com/britzl 30 | [jaysonesmith]: https://github.com/jaysonesmith 31 | [joshski]: https://github.com/joshski 32 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem "cucumber" 4 | gem "aruba" 5 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | aruba (0.6.2) 5 | childprocess (>= 0.3.6) 6 | cucumber (>= 1.1.1) 7 | rspec-expectations (>= 2.7.0) 8 | builder (3.2.2) 9 | childprocess (0.5.5) 10 | ffi (~> 1.0, >= 1.0.11) 11 | cucumber (1.3.19) 12 | builder (>= 2.1.2) 13 | diff-lcs (>= 1.1.3) 14 | gherkin (~> 2.12) 15 | multi_json (>= 1.7.5, < 2.0) 16 | multi_test (>= 0.1.2) 17 | diff-lcs (1.2.5) 18 | ffi (1.13.1) 19 | gherkin (2.12.2) 20 | multi_json (~> 1.3) 21 | multi_json (1.10.1) 22 | multi_test (0.1.2) 23 | rspec-expectations (3.2.0) 24 | diff-lcs (>= 1.2.0, < 2.0) 25 | rspec-support (~> 3.2.0) 26 | rspec-support (3.2.2) 27 | 28 | PLATFORMS 29 | ruby 30 | 31 | DEPENDENCIES 32 | aruba 33 | cucumber 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2012 Josh Chisholm 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | spec : 2 | lua spec/runner.lua 3 | 4 | cuke : 5 | luarocks install cucumber-lua-0.0-2.rockspec 6 | cucumber 7 | 8 | install : 9 | luarocks install luafilesystem 10 | luarocks install luasocket 11 | luarocks install luajson 12 | 13 | .PHONY: spec install 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cucumber-Lua 2 | [![Build Status](https://travis-ci.org/cucumber/cucumber-lua.svg?branch=master)](https://travis-ci.org/cucumber/cucumber-lua) 3 | 4 | A [wire protocol](https://github.com/cucumber/cucumber-ruby-wire) server for [cucumber-ruby](http://github.com/cucumber/cucumber-ruby) that executes steps defined in [Lua](http://www.lua.org/) 5 | 6 | #### Installation 7 | 8 | 1. Install Lua 5.2 9 | 10 | 2. Install cucumber-lua using luarocks: 11 | 12 | ``` 13 | luarocks build https://raw.github.com/cucumber/cucumber-lua/master/cucumber-lua-0.0-2.rockspec 14 | ``` 15 | 16 | 3. Install [Ruby]([url](https://www.ruby-lang.org/en/documentation/installation/)), [cucumber-ruby]([url](http://github.com/cucumber/cucumber-ruby)) and the [wire protocol gem]([url](https://github.com/cucumber/cucumber-ruby-wire)). 17 | 18 | Create a `Gemfile` 19 | 20 | ``` 21 | source 'https://rubygems.org' 22 | 23 | gem "cucumber" 24 | gem "cucumber-wire" 25 | ``` 26 | 27 | Then ask [Bundler]([url](https://bundler.io/)) to install the gems: 28 | 29 | bundle install 30 | 31 | Add a file to load the wire protocol plugin: 32 | 33 | echo "require 'cucumber/wire'" > features/support/wire.rb 34 | 35 | 5. Add a .wire file telling cucumber that Lua is listening: 36 | 37 | ###### /features/step_definitions/cucumber-lua.wire 38 | 39 | ``` 40 | host: 0.0.0.0 41 | port: 9666 42 | ``` 43 | 44 | #### Usage 45 | 46 | Run the cucumber-lua server: 47 | 48 | ``` 49 | cucumber-lua 50 | ``` 51 | 52 | Then run cucumber in another terminal: 53 | 54 | ``` 55 | bundle exec cucumber 56 | ``` 57 | 58 | #### Lua Step Definitions 59 | 60 | cucumber-lua expects you to define a single file for step definitions (features/step_definitions/steps.lua). If you need anything more than a single file, use lua modules and require them from your main steps file (that means we don't need luafilesystem). 61 | 62 | Create your step definitions using the following global keywords: 63 | 64 | * `Before(fn)` - called before each scenario 65 | * `After(fn)` - called after each scenario 66 | * `Given(step, fn)` - define a step where a pre-condition/state is declared 67 | * `When(step, fn)` - define a step where user action or behaviour is performed 68 | * `Then(step, fn)` - define a step where the outcome is observed 69 | * `Pending(message)` - indicate a step as pending implementation 70 | 71 | Note: If a `Before` or `After` function fails the whole scenario is reported as failed. 72 | 73 | ###### /features/step_definitions/steps.lua 74 | 75 | ```Lua 76 | Calculator = require("calculator") 77 | 78 | Before(function() 79 | Calculator:Reset() 80 | end) 81 | 82 | After(function() 83 | print("I am called after each scenario") 84 | end) 85 | 86 | Given("I have entered (%d+) into the calculator", function (number) 87 | Calculator:Enter(number) 88 | end) 89 | 90 | When("I press add", function () 91 | Calculator:Add() 92 | end) 93 | 94 | Then("the result should be (%d+) on the screen", function (number) 95 | assert(Calculator.result == tonumber(number), 96 | "Expected " .. number .. ", was " .. Calculator.result) 97 | end) 98 | 99 | Then("Something not yet implemented", function () 100 | Pending("It's not ready yet") 101 | end) 102 | ``` 103 | 104 | #### Running the Cucumber-Lua specs 105 | 106 | ``` 107 | lua spec/runner.lua 108 | ``` 109 | -------------------------------------------------------------------------------- /bin/cucumber-lua: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env lua 2 | 3 | require("cucumber"):StartListening() -------------------------------------------------------------------------------- /cucumber-lua-0.0-2.rockspec: -------------------------------------------------------------------------------- 1 | package = "Cucumber-Lua" 2 | version = "0.0-2" 3 | source = { 4 | url = "git://github.com/cucumber/cucumber-lua.git" 5 | } 6 | description = { 7 | summary = "A cucumber wire protocol implementation", 8 | detailed = [[ 9 | A wire protocol implementation for cucumber that 10 | executes steps defined in Lua 11 | ]], 12 | homepage = "http://github.com/cucumber/cucumber-lua", 13 | maintainer = "Josh Chisholm, Featurist ", 14 | license = "MIT" 15 | } 16 | dependencies = { 17 | "lua >= 5.1", 18 | "luasocket >= 2.0", 19 | "luajson >= 1.3" 20 | } 21 | build = { 22 | type = "builtin", 23 | modules = { 24 | cucumber = "src/cucumber.lua" 25 | }, 26 | install = { 27 | bin = { "bin/cucumber-lua" } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /examples/calculator/calculator.lua: -------------------------------------------------------------------------------- 1 | Calculator = { numbers = {} } 2 | 3 | function Calculator:Reset () 4 | self.numbers = {} 5 | end 6 | 7 | function Calculator:Enter (number) 8 | table.insert(self.numbers, number) 9 | end 10 | 11 | function Calculator:Add () 12 | self.result = 0 13 | for i = 1, #self.numbers do 14 | self.result = self.result + self.numbers[i] 15 | end 16 | end 17 | 18 | return Calculator -------------------------------------------------------------------------------- /examples/calculator/features/addition.feature: -------------------------------------------------------------------------------- 1 | Feature: Addition 2 | In order to avoid silly mistakes 3 | As a math idiot 4 | I want to be told the sum of two numbers 5 | 6 | Scenario Outline: Add two numbers 7 | Given I have entered into the calculator 8 | And I have entered into the calculator 9 | When I press