Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions features/docs/defining_steps/assertions.feature
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
@spawn
@spawn @wip
Feature: Assertions

Assertions are how you tell Cucumber that a step has failed. The most basic
way to do this is by raising an exception, but you can also use Ruby's built-in
`Test::Unit` assertions library, or RSpec's `RSpec::Expectations` library.
`MiniTest::Unit` or `Test::Unit` assertions library, the `minitest` gem with
assertions in `Minitest::Assertions` or RSpec's `RSpec::Expectations` library.

Background:
Given a file named "features/assert.feature" with:
Expand Down
64 changes: 49 additions & 15 deletions lib/cucumber/rb_support/rb_language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,29 @@
require 'cucumber/rb_support/rb_transform'
require 'cucumber/rb_support/snippet'

begin
require 'rspec/expectations'
rescue LoadError
begin
[
proc { require 'rspec/expectations' },

proc do
require 'spec/expectations'
require 'spec/runner/differs/default'
require 'ostruct'
rescue LoadError
require 'test/unit/assertions'
end
end,

proc { require 'minitest/assertions' },

proc { require 'minitest/unit' },

proc { require 'test/unit/assertions' },
].each do | load_proc |
result =
begin
load_proc.call
rescue LoadError
next
end

break if result
end

module Cucumber
Expand Down Expand Up @@ -59,18 +72,39 @@ def initialize(runtime)
end

def find_best_assertions_module
begin
::RSpec::Matchers
rescue NameError
# RSpec >=1.2.4
begin
result = nil

##
# The order of these procs should match the order
# of the procs defined at the top of this file in
# order to search for constants in the same order
#
[
proc { ::RSpec::Matchers },

proc do
options = OpenStruct.new(:diff_format => :unified, :context_lines => 3)
Spec::Expectations.differ = Spec::Expectations::Differs::Default.new(options)
::Spec::Matchers
rescue NameError
::Test::Unit::Assertions
end
end,

proc { ::Minitest::Assertions },

proc { ::MiniTest::Assertions },

proc { ::Test::Unit::Assertions },
].each do | search_proc |
result =
begin
search_proc.call
rescue NameError
next
end

break if result
end

result
end

def step_matches(name_to_match, name_to_format)
Expand Down