Skip to content

Commit

Permalink
Add feature for CoffeeScript support (close #29)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbpros committed Oct 12, 2011
1 parent 07e8490 commit 6ae8b2d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
11 changes: 11 additions & 0 deletions features/coffeescript_support.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: CoffeeScript support
In order to use the JS dialect I'm most comfortable with
As a step definition implementor
I want to use CoffeeScript for writing step definitions

Scenario: CoffeeScript step definition
Given a mapping written in CoffeeScript
When Cucumber executes a scenario using that mapping
Then the feature passes
And the mapping is run

17 changes: 15 additions & 2 deletions features/step_definitions/cucumber_js_mappings.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module CucumberJsMappings
STEP_DEFINITIONS_FILE = "features/step_definitions/cucumber_steps.js"
FEATURE_FILE = "features/a_feature.feature"
STEP_DEFINITIONS_FILE = "features/step_definitions/cucumber_steps.js"
COFFEE_SCRIPT_DEFINITIONS_FILE = "features/step_definitions/cucumber_steps.coffee"
FEATURE_FILE = "features/a_feature.feature"

attr_accessor :support_code

Expand Down Expand Up @@ -112,6 +113,18 @@ def write_main_step_definitions_file
append_to_file(STEP_DEFINITIONS_FILE, "};\nmodule.exports = stepDefinitions;")
end

def write_coffee_script_definition_file
append_to_file COFFEE_SCRIPT_DEFINITIONS_FILE, <<-EOF
fs = require('fs')
stepDefinitions = () ->
this.defineStep(/^a mapping$/, (callback) ->
fs.writeFileSync('a_mapping.step', '')
callback()
)
module.exports = stepDefinitions
EOF
end

def get_file_contents(file_path)
file_realpath = File.expand_path(file_path, File.dirname(__FILE__))
File.open(file_realpath, 'rb') do |f|
Expand Down
19 changes: 19 additions & 0 deletions features/step_definitions/cucumber_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file contains step definitions which are relevant to
# Cucumber.js feature suite only.

Given /^a mapping written in CoffeeScript$/ do
write_coffee_script_definition_file
end

When /^Cucumber executes a scenario using that mapping$/ do
write_feature <<-EOF
Feature:
Scenario:
Given a mapping
EOF
run_feature
end

Then /^the mapping is run$/ do
assert_passed "a mapping"
end

0 comments on commit 6ae8b2d

Please sign in to comment.