Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' into ast-cleanup

  • Loading branch information...
commit 1d2be944eb7e6d9ff255fd2fbe673ec2b3982c95 2 parents 7a6b24d + a3439ce
@mattwynne mattwynne authored
View
10 History.md
@@ -1,9 +1,17 @@
## [Git master](https://github.com/cucumber/cucumber/compare/v1.2.3...master)
### New Features
+* Add lib to default load path
+ ([#162](https://github.com/cucumber/cucumber/issues/162) Steve Tooke)
### Bugfixes
-* Fix problem with non-ascii characters in file path ([#150](https://github.com/cucumber/cucumber/issues/150) Oleg Sukhodolsky)
+* Filter out control characters from CDATA section of JUnit formatter output. ([#383](https://github.com/cucumber/cucumber/issues/383) @teacup-on-rockingchair)
+* Fix problem with non-ascii characters in file path
+ ([#150](https://github.com/cucumber/cucumber/issues/150) Oleg Sukhodolsky)
+* Fix problem loading ruby files in project root directory
+ ([#269](https://github.com/cucumber/cucumber/issues/269) Steve Tooke)
+* Fix JsonPretty formatter problem
+ ([#197](https://github.com/cucumber/cucumber/issues/197) Oleg Sukhodolsky)
## [1.2.3](https://github.com/cucumber/cucumber/compare/v1.2.2...v1.2.3)
View
14 features/bootstrap.feature
@@ -11,3 +11,17 @@ Feature: Bootstrapping a new project
You don't have a 'features' directory. Please create one to get started.
See http://cukes.info/ for more information.
"""
+
+ Scenario: does not load ruby files in root if features directory is missing
+ Given a directory without standard Cucumber project directory structure
+ And a file named "should_not_load.rb" with:
+ """
+ puts 'this will not be shown'
+ """
+ When I run `cucumber`
+ Then it should fail with exactly:
+ """
+ You don't have a 'features' directory. Please create one to get started.
+ See http://cukes.info/ for more information.
+
+ """
View
89 features/json_formatter.feature
@@ -144,12 +144,95 @@ Feature: JSON output formatter
"""
@wip-jruby
+ Scenario: one feature, one passing scenario, one failing scenario with prettyfied json
+ When I run cucumber "--format json_pretty features/one_passing_one_failing.feature"
+ Then it should fail with JSON:
+ """
+ [
+ {
+ "uri": "features/one_passing_one_failing.feature",
+ "keyword": "Feature",
+ "id": "one-passing-scenario,-one-failing-scenario",
+ "name": "One passing scenario, one failing scenario",
+ "line": 2,
+ "description": "",
+ "tags": [
+ {
+ "name": "@a",
+ "line": 1
+ }
+ ],
+ "elements": [
+ {
+ "keyword": "Scenario",
+ "id": "one-passing-scenario,-one-failing-scenario;passing",
+ "name": "Passing",
+ "line": 5,
+ "description": "",
+ "tags": [
+ {
+ "name": "@b",
+ "line": 4
+ }
+ ],
+ "type": "scenario",
+ "steps": [
+ {
+ "keyword": "Given ",
+ "name": "a passing step",
+ "line": 6,
+ "match": {
+ "location": "features/step_definitions/steps.rb:1"
+ },
+ "result": {
+ "status": "passed",
+ "duration": 1
+ }
+ }
+ ]
+ },
+ {
+ "keyword": "Scenario",
+ "id": "one-passing-scenario,-one-failing-scenario;failing",
+ "name": "Failing",
+ "line": 9,
+ "description": "",
+ "tags": [
+ {
+ "name": "@c",
+ "line": 8
+ }
+ ],
+ "type": "scenario",
+ "steps": [
+ {
+ "keyword": "Given ",
+ "name": "a failing step",
+ "line": 10,
+ "match": {
+ "location": "features/step_definitions/steps.rb:5"
+ },
+ "result": {
+ "status": "failed",
+ "error_message": " (RuntimeError)\n./features/step_definitions/steps.rb:6:in `/a failing step/'\nfeatures/one_passing_one_failing.feature:10:in `Given a failing step'",
+ "duration": 1
+ }
+ }
+ ]
+ }
+ ]
+ }
+ ]
+
+ """
+
+ @wip-jruby
Scenario: DocString
Given a file named "features/doc_string.feature" with:
"""
Feature: A DocString feature
- Scenario:
+ Scenario:
Then I should fail with
\"\"\"
a string
@@ -186,8 +269,8 @@ Feature: JSON output formatter
"name": "I should fail with",
"line": 4,
"doc_string": {
- "content_type": "",
- "value": "a string",
+ "content_type": "",
+ "value": "a string",
"line": 5
},
"match": {
View
14 features/load_path.feature
@@ -0,0 +1,14 @@
+Feature: Set up a default load path
+
+ Scenario: ./lib is included in the $LOAD_PATH
+ Given a file named "features/support/env.rb" with:
+ """
+ require 'something'
+ """
+ And a file named "lib/something.rb" with:
+ """
+ class Something
+ end
+ """
+ When I run `cucumber`
+ Then it should pass
View
13 lib/cucumber/cli/configuration.rb
@@ -106,7 +106,7 @@ def support_to_load
end
def feature_files
- potential_feature_files = paths.map do |path|
+ potential_feature_files = with_default_features_path(paths).map do |path|
path = path.gsub(/\\/, '/') # In case we're on windows. Globs don't work with backslashes.
path = path.chomp('/')
if File.directory?(path)
@@ -123,7 +123,9 @@ def feature_files
end
def feature_dirs
- paths.map { |f| File.directory?(f) ? f : File.dirname(f) }.uniq
+ dirs = paths.map { |f| File.directory?(f) ? f : File.dirname(f) }.uniq
+ dirs.delete('.') unless paths.include?('.')
+ with_default_features_path(dirs)
end
def log
@@ -152,9 +154,14 @@ def options
end
def paths
- @options[:paths].empty? ? ['features'] : @options[:paths]
+ @options[:paths]
end
private
+ def with_default_features_path(paths)
+ return ['features'] if paths.empty?
+ paths
+ end
+
def formatters(runtime)
# TODO: We should remove the autoformat functionality. That
View
8 lib/cucumber/formatter/gherkin_formatter_adapter.rb
@@ -6,9 +6,9 @@ module Formatter
# Adapts Cucumber formatter events to Gherkin formatter events
# This class will disappear when Cucumber is based on Gherkin's model.
class GherkinFormatterAdapter
- def initialize(gherkin_formatter, print_emtpy_match)
+ def initialize(gherkin_formatter, print_empty_match)
@gf = gherkin_formatter
- @print_emtpy_match = print_emtpy_match
+ @print_empty_match = print_empty_match
end
def before_feature(feature)
@@ -36,7 +36,7 @@ def before_feature_element(feature_element)
def before_step(step)
@gf.step(step.gherkin_statement)
- if @print_emtpy_match
+ if @print_empty_match
if(@outline)
match = Gherkin::Formatter::Model::Match.new(step.gherkin_statement.outline_args, nil)
else
@@ -51,7 +51,7 @@ def before_step_result(keyword, step_match, multiline_arg, status, exception, so
arguments = step_match.step_arguments.map{|a| Gherkin::Formatter::Argument.new(a.offset, a.val)}
location = step_match.file_colon_line
match = Gherkin::Formatter::Model::Match.new(arguments, location)
- if @print_emtpy_match
+ if @print_empty_match
# Trick the formatter to believe that's what was printed previously so we get arg highlights on #result
@gf.instance_variable_set('@match', match)
else
View
4 lib/cucumber/formatter/json_pretty.rb
@@ -1,13 +1,9 @@
-require 'multi_json'
require 'cucumber/formatter/json'
module Cucumber
module Formatter
# The formatter used for <tt>--format json_pretty</tt>
class JsonPretty < Json
- def after_features(features)
- @io.write(MultiJson.dump(@obj, :pretty => true))
- end
end
end
end
View
10 lib/cucumber/formatter/junit.rb
@@ -48,10 +48,10 @@ def after_feature(feature)
:name => @feature_name ) do
@testsuite << @builder.target!
@testsuite.tag!('system-out') do
- @testsuite.cdata! @interceptedout.buffer.join
+ @testsuite.cdata! strip_control_chars(@interceptedout.buffer.join)
end
@testsuite.tag!('system-err') do
- @testsuite.cdata! @interceptederr.buffer.join
+ @testsuite.cdata! strip_control_chars(@interceptederr.buffer.join)
end
end
@@ -166,6 +166,12 @@ def basename(feature_file)
def write_file(feature_filename, data)
File.open(feature_filename, 'w') { |file| file.write(data) }
end
+
+ # strip control chars from cdata, to make it safe for external parsers
+ def strip_control_chars(cdata)
+ cdata.scan(/[[:print:]\t\n\r]/).join
+ end
+
end
end
end
View
13 lib/cucumber/load_path.rb
@@ -0,0 +1,13 @@
+module Cucumber
+ module LoadPath
+ def add_dirs(*dirs)
+ dirs.each do |dir|
+ $LOAD_PATH.unshift(dir) unless $LOAD_PATH.include?(dir)
+ end
+ end
+
+ module_function :add_dirs
+ end
+end
+
+Cucumber::LoadPath.add_dirs('lib')
View
1  lib/cucumber/runtime.rb
@@ -3,6 +3,7 @@
require 'gherkin/rubify'
require 'gherkin/i18n'
require 'cucumber/configuration'
+require 'cucumber/load_path'
require 'cucumber/language_support/language_methods'
require 'cucumber/formatter/duration'
require 'cucumber/runtime/user_interface'
View
33 spec/cucumber/formatter/junit_spec.rb
@@ -23,6 +23,39 @@ def write_file(feature_filename, data)
@formatter = TestDoubleJunitFormatter.new(step_mother, '', {})
end
+ describe "should be able to strip control chars from cdata" do
+ before(:each) do
+ run_defined_feature
+ @doc = Nokogiri.XML(@formatter.written_files.values.first)
+ end
+ define_feature "
+ Feature: One passing scenario, one failing scenario
+
+ Scenario: Passing
+ Given a passing ctrl scenario
+ "
+ class Junit
+ def before_step(step)
+ if step.name.match("a passing ctrl scenario")
+ Interceptor::Pipe.unwrap! :stdout
+ @fake_io = $stdout = StringIO.new
+ $stdout.sync = true
+ @interceptedout = Interceptor::Pipe.wrap(:stdout)
+ end
+ end
+
+ def after_step(step)
+ if step.name.match("a passing ctrl scenario")
+ @interceptedout.write("boo\b\cx\e\a\f boo ")
+ $stdout = STDOUT
+ @fake_io.close
+ end
+ end
+ end
+
+ it { @doc.xpath('//testsuite/system-out').first.content.should match(/\s+boo boo\s+/) }
+ end
+
describe "a feature with no name" do
define_feature <<-FEATURE
Feature:
Please sign in to comment.
Something went wrong with that request. Please try again.