Skip to content

Commit

Permalink
Made snippets configurable so they get printed differently on Java/JB…
Browse files Browse the repository at this point in the history
…ehave
  • Loading branch information
aslakhellesoy committed Jan 24, 2009
1 parent 7c7cdc3 commit 4c93a50
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions examples/jbehave/features/trading.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ Feature: Trading
Given a stock of prices 0.5,1.0 and a threshold of 1.5
When the stock is traded at 2.0
Then the trader sells all stocks
And the trader gets a bonus
1 change: 1 addition & 0 deletions lib/cucumber/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class << self
def step_mother=(step_mother)
@step_mother = step_mother
@step_mother.extend(StepMother)
@step_mother.snippet_generator = StepDefinition
end

def execute(args)
Expand Down
6 changes: 1 addition & 5 deletions lib/cucumber/formatter/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def print_snippets(io, features, options)
return if undefined.empty?
snippets = undefined.map do |step|
step_name = StepMother::Undefined === step.exception ? step.exception.step_name : step.name
snippet = "#{step.actual_keyword} /^#{escape_regexp_characters(step_name)}$/ do\nend"
snippet = @step_mother.snippet_text(step.actual_keyword, step_name)
snippet
end.compact.uniq

Expand All @@ -102,10 +102,6 @@ def format_for(*keys)
raise "No format for #{key.inspect}: #{FORMATS.inspect}" if fmt.nil?
fmt
end

def escape_regexp_characters(string)
Regexp.escape(string).gsub('\ ', ' ').gsub('/', '\/') unless string.nil?
end
end
end
end
11 changes: 10 additions & 1 deletion lib/cucumber/jbehave.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ def java_exception_to_ruby_exception(java_exception)
end

REPORTER = Reporter.new

def self.snippet_text(step_keyword, step_name)
camel = step_name.gsub(/(\s.)/) {$1.upcase.strip}
method = camel[0..0].downcase + camel[1..-1]
snippet = %{ @#{step_keyword}("#{step_name}")
public void #{method}() {
}}
end
end
end

self.extend(Cucumber::JBehave)
self.extend(Cucumber::JBehave)
self.snippet_generator = Cucumber::JBehave
5 changes: 5 additions & 0 deletions lib/cucumber/step_definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ module Cucumber
# end
#
class StepDefinition
def self.snippet_text(step_keyword, step_name)
escaped = Regexp.escape(step_name).gsub('\ ', ' ').gsub('/', '\/')
"#{step_keyword} /^#{escaped}$/ do\nend"
end

class MissingProc < StandardError
def message
"Step definitions must always have a proc"
Expand Down
6 changes: 6 additions & 0 deletions lib/cucumber/step_mother.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module Cucumber
# so #register_step_definition (and more interestingly - its aliases) are
# available from the top-level.
module StepMother
attr_writer :snippet_generator

class Undefined < StandardError
attr_reader :step_name

Expand Down Expand Up @@ -118,6 +120,10 @@ def step_definitions
@step_definitions ||= []
end

def snippet_text(step_keyword, step_name)
@snippet_generator.snippet_text(step_keyword, step_name)
end

module WorldMethods #:nodoc:
attr_writer :__cucumber_step_mother, :__cucumber_current_step

Expand Down

0 comments on commit 4c93a50

Please sign in to comment.