rspec-expectations 3.0.0.beta2 → 3.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -2
- data/.yardopts +0 -1
- data/Changelog.md +115 -35
- data/README.md +2 -2
- data/lib/rspec/expectations.rb +13 -8
- data/lib/rspec/{matchers → expectations}/configuration.rb +38 -13
- data/lib/rspec/expectations/expectation_target.rb +72 -8
- data/lib/rspec/expectations/fail_with.rb +10 -52
- data/lib/rspec/expectations/handler.rb +9 -11
- data/lib/rspec/expectations/syntax.rb +37 -35
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers.rb +60 -9
- data/lib/rspec/matchers/aliased_matcher.rb +6 -0
- data/lib/rspec/matchers/built_in.rb +9 -1
- data/lib/rspec/matchers/built_in/all.rb +78 -0
- data/lib/rspec/matchers/built_in/base_matcher.rb +39 -1
- data/lib/rspec/matchers/built_in/be.rb +117 -42
- data/lib/rspec/matchers/built_in/be_between.rb +22 -0
- data/lib/rspec/matchers/built_in/be_instance_of.rb +11 -3
- data/lib/rspec/matchers/built_in/be_kind_of.rb +5 -0
- data/lib/rspec/matchers/built_in/be_within.rb +26 -6
- data/lib/rspec/matchers/built_in/change.rb +89 -13
- data/lib/rspec/matchers/built_in/compound.rb +19 -3
- data/lib/rspec/matchers/built_in/contain_exactly.rb +17 -6
- data/lib/rspec/matchers/built_in/cover.rb +3 -0
- data/lib/rspec/matchers/built_in/eq.rb +20 -5
- data/lib/rspec/matchers/built_in/eql.rb +15 -3
- data/lib/rspec/matchers/built_in/equal.rb +23 -6
- data/lib/rspec/matchers/built_in/exist.rb +74 -10
- data/lib/rspec/matchers/built_in/has.rb +58 -3
- data/lib/rspec/matchers/built_in/include.rb +16 -1
- data/lib/rspec/matchers/built_in/match.rb +14 -4
- data/lib/rspec/matchers/built_in/operators.rb +16 -0
- data/lib/rspec/matchers/built_in/output.rb +47 -5
- data/lib/rspec/matchers/built_in/raise_error.rb +40 -23
- data/lib/rspec/matchers/built_in/respond_to.rb +37 -16
- data/lib/rspec/matchers/built_in/satisfy.rb +15 -0
- data/lib/rspec/matchers/built_in/start_and_end_with.rb +29 -14
- data/lib/rspec/matchers/built_in/throw_symbol.rb +32 -3
- data/lib/rspec/matchers/built_in/yield.rb +148 -44
- data/lib/rspec/matchers/composable.rb +48 -7
- data/lib/rspec/matchers/dsl.rb +45 -17
- data/lib/rspec/matchers/generated_descriptions.rb +7 -0
- data/lib/rspec/matchers/matcher_delegator.rb +6 -2
- data/lib/rspec/matchers/pretty.rb +15 -19
- metadata +33 -236
- metadata.gz.sig +0 -0
- data/features/README.md +0 -48
- data/features/Upgrade.md +0 -53
- data/features/built_in_matchers/README.md +0 -96
- data/features/built_in_matchers/be.feature +0 -175
- data/features/built_in_matchers/be_within.feature +0 -48
- data/features/built_in_matchers/comparisons.feature +0 -97
- data/features/built_in_matchers/contain_exactly.feature +0 -46
- data/features/built_in_matchers/cover.feature +0 -47
- data/features/built_in_matchers/end_with.feature +0 -48
- data/features/built_in_matchers/equality.feature +0 -136
- data/features/built_in_matchers/exist.feature +0 -45
- data/features/built_in_matchers/expect_change.feature +0 -59
- data/features/built_in_matchers/expect_error.feature +0 -144
- data/features/built_in_matchers/include.feature +0 -126
- data/features/built_in_matchers/match.feature +0 -51
- data/features/built_in_matchers/output.feature +0 -70
- data/features/built_in_matchers/predicates.feature +0 -161
- data/features/built_in_matchers/respond_to.feature +0 -84
- data/features/built_in_matchers/satisfy.feature +0 -33
- data/features/built_in_matchers/start_with.feature +0 -48
- data/features/built_in_matchers/throw_symbol.feature +0 -91
- data/features/built_in_matchers/types.feature +0 -116
- data/features/built_in_matchers/yield.feature +0 -161
- data/features/composing_matchers.feature +0 -250
- data/features/compound_expectations.feature +0 -45
- data/features/custom_matchers/access_running_example.feature +0 -53
- data/features/custom_matchers/define_diffable_matcher.feature +0 -27
- data/features/custom_matchers/define_matcher.feature +0 -340
- data/features/custom_matchers/define_matcher_outside_rspec.feature +0 -34
- data/features/custom_matchers/define_matcher_with_fluent_interface.feature +0 -24
- data/features/customized_message.feature +0 -39
- data/features/diffing.feature +0 -85
- data/features/implicit_docstrings.feature +0 -52
- data/features/step_definitions/additional_cli_steps.rb +0 -22
- data/features/support/env.rb +0 -21
- data/features/support/rubinius.rb +0 -6
- data/features/syntax_configuration.feature +0 -71
- data/features/test_frameworks/minitest.feature +0 -44
- data/lib/rspec-expectations.rb +0 -1
- data/lib/rspec/expectations/diff_presenter.rb +0 -141
- data/lib/rspec/expectations/differ.rb +0 -44
- data/lib/rspec/expectations/encoded_string.rb +0 -56
- data/spec/rspec/expectations/diff_presenter_spec.rb +0 -249
- data/spec/rspec/expectations/encoded_string_spec.rb +0 -74
- data/spec/rspec/expectations/expectation_target_spec.rb +0 -82
- data/spec/rspec/expectations/extensions/kernel_spec.rb +0 -67
- data/spec/rspec/expectations/fail_with_spec.rb +0 -114
- data/spec/rspec/expectations/handler_spec.rb +0 -205
- data/spec/rspec/expectations/minitest_integration_spec.rb +0 -27
- data/spec/rspec/expectations/syntax_spec.rb +0 -89
- data/spec/rspec/expectations_spec.rb +0 -12
- data/spec/rspec/matchers/aliased_matcher_spec.rb +0 -48
- data/spec/rspec/matchers/aliases_spec.rb +0 -449
- data/spec/rspec/matchers/built_in/base_matcher_spec.rb +0 -83
- data/spec/rspec/matchers/built_in/be_between_spec.rb +0 -159
- data/spec/rspec/matchers/built_in/be_instance_of_spec.rb +0 -63
- data/spec/rspec/matchers/built_in/be_kind_of_spec.rb +0 -41
- data/spec/rspec/matchers/built_in/be_spec.rb +0 -592
- data/spec/rspec/matchers/built_in/be_within_spec.rb +0 -141
- data/spec/rspec/matchers/built_in/change_spec.rb +0 -808
- data/spec/rspec/matchers/built_in/compound_spec.rb +0 -292
- data/spec/rspec/matchers/built_in/contain_exactly_spec.rb +0 -441
- data/spec/rspec/matchers/built_in/cover_spec.rb +0 -69
- data/spec/rspec/matchers/built_in/eq_spec.rb +0 -156
- data/spec/rspec/matchers/built_in/eql_spec.rb +0 -41
- data/spec/rspec/matchers/built_in/equal_spec.rb +0 -106
- data/spec/rspec/matchers/built_in/exist_spec.rb +0 -124
- data/spec/rspec/matchers/built_in/has_spec.rb +0 -161
- data/spec/rspec/matchers/built_in/include_spec.rb +0 -540
- data/spec/rspec/matchers/built_in/match_spec.rb +0 -102
- data/spec/rspec/matchers/built_in/operators_spec.rb +0 -252
- data/spec/rspec/matchers/built_in/output_spec.rb +0 -165
- data/spec/rspec/matchers/built_in/raise_error_spec.rb +0 -461
- data/spec/rspec/matchers/built_in/respond_to_spec.rb +0 -292
- data/spec/rspec/matchers/built_in/satisfy_spec.rb +0 -44
- data/spec/rspec/matchers/built_in/start_and_end_with_spec.rb +0 -253
- data/spec/rspec/matchers/built_in/throw_symbol_spec.rb +0 -135
- data/spec/rspec/matchers/built_in/yield_spec.rb +0 -627
- data/spec/rspec/matchers/configuration_spec.rb +0 -213
- data/spec/rspec/matchers/description_generation_spec.rb +0 -191
- data/spec/rspec/matchers/dsl_spec.rb +0 -895
- data/spec/rspec/matchers/legacy_spec.rb +0 -101
- data/spec/rspec/matchers_spec.rb +0 -74
- data/spec/spec_helper.rb +0 -85
- data/spec/support/matchers.rb +0 -22
- data/spec/support/shared_examples.rb +0 -35
@@ -1,34 +0,0 @@
|
|
1
|
-
Feature: define matcher outside rspec
|
2
|
-
|
3
|
-
In order to express my domain clearly in my code examples
|
4
|
-
As a non-rspec user
|
5
|
-
I want a shortcut to define custom matchers
|
6
|
-
|
7
|
-
Scenario: define a matcher with default messages
|
8
|
-
Given a file named "test_multiples.rb" with:
|
9
|
-
"""ruby
|
10
|
-
require "minitest/autorun"
|
11
|
-
require "rspec/expectations/minitest_integration"
|
12
|
-
|
13
|
-
RSpec::Matchers.define :be_a_multiple_of do |expected|
|
14
|
-
match do |actual|
|
15
|
-
actual % expected == 0
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class TestMultiples < Minitest::Test
|
20
|
-
|
21
|
-
def test_9_should_be_a_multiple_of_3
|
22
|
-
expect(9).to be_a_multiple_of(3)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_9_should_be_a_multiple_of_4
|
26
|
-
expect(9).to be_a_multiple_of(4)
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
"""
|
31
|
-
When I run `ruby test_multiples.rb`
|
32
|
-
Then the exit status should not be 0
|
33
|
-
And the output should contain "expected 9 to be a multiple of 4"
|
34
|
-
And the output should contain "2 runs, 2 assertions, 1 failures, 0 errors"
|
@@ -1,24 +0,0 @@
|
|
1
|
-
Feature: define matcher with fluent interface
|
2
|
-
|
3
|
-
Use the chain() method to define matchers with a fluent interface.
|
4
|
-
|
5
|
-
Scenario: chained method with argument
|
6
|
-
Given a file named "between_spec.rb" with:
|
7
|
-
"""ruby
|
8
|
-
RSpec::Matchers.define :be_bigger_than do |first|
|
9
|
-
match do |actual|
|
10
|
-
(actual > first) && (actual < @second)
|
11
|
-
end
|
12
|
-
|
13
|
-
chain :but_smaller_than do |second|
|
14
|
-
@second = second
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe 5 do
|
19
|
-
it { should be_bigger_than(4).but_smaller_than(6) }
|
20
|
-
end
|
21
|
-
"""
|
22
|
-
When I run `rspec between_spec.rb --format documentation`
|
23
|
-
Then the output should contain "1 example, 0 failures"
|
24
|
-
And the output should contain "should be bigger than 4"
|
@@ -1,39 +0,0 @@
|
|
1
|
-
Feature: customized message
|
2
|
-
|
3
|
-
RSpec tries to provide useful failure messages, but for cases in which you
|
4
|
-
want more specific information, you can define your own message right in the
|
5
|
-
example. This works for any matcher _other than the operator matchers_.
|
6
|
-
|
7
|
-
Scenario: customize failure message
|
8
|
-
Given a file named "example_spec.rb" with:
|
9
|
-
"""ruby
|
10
|
-
describe Array do
|
11
|
-
context "when created with `new`" do
|
12
|
-
it "is empty" do
|
13
|
-
array = Array.new
|
14
|
-
array << 1 # trigger a failure to demonstrate the message
|
15
|
-
expect(array).to be_empty, "expected empty array, got #{array.inspect}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
"""
|
21
|
-
When I run `rspec example_spec.rb --format documentation`
|
22
|
-
Then the output should contain "expected empty array, got [1]"
|
23
|
-
|
24
|
-
Scenario: customize failure message with a proc
|
25
|
-
Given a file named "example_spec.rb" with:
|
26
|
-
"""ruby
|
27
|
-
describe Array do
|
28
|
-
context "when created with `new`" do
|
29
|
-
it "is empty" do
|
30
|
-
array = Array.new
|
31
|
-
array << 1 # trigger a failure to demonstrate the message
|
32
|
-
expect(array).to be_empty, lambda { "expected empty array, got #{array.inspect}" }
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
"""
|
38
|
-
When I run `rspec example_spec.rb --format documentation`
|
39
|
-
Then the output should contain "expected empty array, got [1]"
|
data/features/diffing.feature
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
Feature: diffing
|
2
|
-
|
3
|
-
When appropriate, failure messages will automatically include a diff.
|
4
|
-
|
5
|
-
Scenario: diff for a multiline string
|
6
|
-
Given a file named "example_spec.rb" with:
|
7
|
-
"""ruby
|
8
|
-
describe "a multiline string" do
|
9
|
-
it "is like another string" do
|
10
|
-
expected = <<-EXPECTED
|
11
|
-
this is the
|
12
|
-
expected
|
13
|
-
string
|
14
|
-
EXPECTED
|
15
|
-
actual = <<-ACTUAL
|
16
|
-
this is the
|
17
|
-
actual
|
18
|
-
string
|
19
|
-
ACTUAL
|
20
|
-
expect(actual).to eq(expected)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
"""
|
24
|
-
When I run `rspec example_spec.rb`
|
25
|
-
Then the output should contain:
|
26
|
-
"""
|
27
|
-
Diff:
|
28
|
-
@@ -1,4 +1,4 @@
|
29
|
-
this is the
|
30
|
-
- expected
|
31
|
-
+ actual
|
32
|
-
string
|
33
|
-
"""
|
34
|
-
|
35
|
-
Scenario: diff for a multiline string and a regexp
|
36
|
-
Given a file named "example_spec.rb" with:
|
37
|
-
"""ruby
|
38
|
-
describe "a multiline string" do
|
39
|
-
it "is like another string" do
|
40
|
-
expected = /expected/m
|
41
|
-
actual = <<-ACTUAL
|
42
|
-
this is the
|
43
|
-
actual
|
44
|
-
string
|
45
|
-
ACTUAL
|
46
|
-
expect(actual).to match expected
|
47
|
-
end
|
48
|
-
end
|
49
|
-
"""
|
50
|
-
When I run `rspec example_spec.rb`
|
51
|
-
Then the output should contain:
|
52
|
-
"""
|
53
|
-
Diff:
|
54
|
-
@@ -1,2 +1,4 @@
|
55
|
-
-/expected/m
|
56
|
-
+this is the
|
57
|
-
+ actual
|
58
|
-
+ string
|
59
|
-
"""
|
60
|
-
|
61
|
-
Scenario: no diff for a single line strings
|
62
|
-
Given a file named "example_spec.rb" with:
|
63
|
-
"""ruby
|
64
|
-
describe "a single line string" do
|
65
|
-
it "is like another string" do
|
66
|
-
expected = "this string"
|
67
|
-
actual = "that string"
|
68
|
-
expect(actual).to eq(expected)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
"""
|
72
|
-
When I run `rspec example_spec.rb`
|
73
|
-
Then the output should not contain "Diff:"
|
74
|
-
|
75
|
-
Scenario: no diff for numbers
|
76
|
-
Given a file named "example_spec.rb" with:
|
77
|
-
"""ruby
|
78
|
-
describe "a number" do
|
79
|
-
it "is like another number" do
|
80
|
-
expect(1).to eq(2)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
"""
|
84
|
-
When I run `rspec example_spec.rb`
|
85
|
-
Then the output should not contain "Diff:"
|
@@ -1,52 +0,0 @@
|
|
1
|
-
Feature: implicit docstrings
|
2
|
-
|
3
|
-
As an RSpec user
|
4
|
-
I want examples to generate their own names
|
5
|
-
So that I can reduce duplication between example names and example code
|
6
|
-
|
7
|
-
Scenario: run passing examples
|
8
|
-
Given a file named "implicit_docstrings_spec.rb" with:
|
9
|
-
"""ruby
|
10
|
-
describe "Examples with no docstrings generate their own:" do
|
11
|
-
|
12
|
-
specify { expect(3).to be < 5 }
|
13
|
-
|
14
|
-
specify { expect([1,2,3]).to include(2) }
|
15
|
-
|
16
|
-
specify { expect([1,2,3]).to respond_to(:size) }
|
17
|
-
|
18
|
-
end
|
19
|
-
"""
|
20
|
-
|
21
|
-
When I run `rspec ./implicit_docstrings_spec.rb -fdoc`
|
22
|
-
|
23
|
-
Then the output should contain "should be < 5"
|
24
|
-
And the output should contain "should include 2"
|
25
|
-
And the output should contain "should respond to #size"
|
26
|
-
|
27
|
-
Scenario: run failing examples
|
28
|
-
Given a file named "failing_implicit_docstrings_spec.rb" with:
|
29
|
-
"""ruby
|
30
|
-
describe "Failing examples with no descriptions" do
|
31
|
-
|
32
|
-
# description is auto-generated as "to equal(5)" based on the last #expect
|
33
|
-
it do
|
34
|
-
expect(3).to equal(2)
|
35
|
-
expect(5).to equal(5)
|
36
|
-
end
|
37
|
-
|
38
|
-
it { expect(3).to be > 5 }
|
39
|
-
|
40
|
-
it { expect([1,2,3]).to include(4) }
|
41
|
-
|
42
|
-
it { expect([1,2,3]).not_to respond_to(:size) }
|
43
|
-
|
44
|
-
end
|
45
|
-
"""
|
46
|
-
|
47
|
-
When I run `rspec ./failing_implicit_docstrings_spec.rb -fdoc`
|
48
|
-
|
49
|
-
Then the output should contain "should equal 2"
|
50
|
-
And the output should contain "should be > 5"
|
51
|
-
And the output should contain "should include 4"
|
52
|
-
And the output should contain "should not respond to #size"
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# Useful for when the output is slightly different on different versions of ruby
|
2
|
-
Then /^the output should contain "([^"]*)" or "([^"]*)"$/ do |string1, string2|
|
3
|
-
unless [string1, string2].any? { |s| all_output =~ regexp(s) }
|
4
|
-
fail %Q{Neither "#{string1}" or "#{string2}" were found in:\n#{all_output}}
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
Then /^the output should contain all of these:$/ do |table|
|
9
|
-
table.raw.flatten.each do |string|
|
10
|
-
assert_partial_output(string, all_output)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
Then /^the example(?:s)? should(?: all)? pass$/ do
|
15
|
-
step %q{the output should contain "0 failures"}
|
16
|
-
step %q{the exit status should be 0}
|
17
|
-
end
|
18
|
-
|
19
|
-
Then /^the example should fail$/ do
|
20
|
-
step %q{the output should contain "1 failure"}
|
21
|
-
step %q{the exit status should not be 0}
|
22
|
-
end
|
data/features/support/env.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'aruba/cucumber'
|
2
|
-
|
3
|
-
Before do
|
4
|
-
if RUBY_PLATFORM =~ /java/ || defined?(Rubinius)
|
5
|
-
@aruba_timeout_seconds = 60
|
6
|
-
else
|
7
|
-
@aruba_timeout_seconds = 10
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
Aruba.configure do |config|
|
12
|
-
config.before_cmd do |cmd|
|
13
|
-
set_env('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived
|
14
|
-
end
|
15
|
-
end if RUBY_PLATFORM == 'java'
|
16
|
-
|
17
|
-
Aruba.configure do |config|
|
18
|
-
config.before_cmd do |cmd|
|
19
|
-
set_env('RBXOPT', "-Xint=true #{ENV['RBXOPT']}") # disable JIT since these processes are so short lived
|
20
|
-
end
|
21
|
-
end if defined?(Rubinius)
|
@@ -1,71 +0,0 @@
|
|
1
|
-
Feature: Syntax Configuration
|
2
|
-
|
3
|
-
In addition to the long-supported `should` syntax, rspec-expectations
|
4
|
-
supports an alternate `expect` syntax. If you want your project to
|
5
|
-
only use one syntax, you can configure the available syntaxes.
|
6
|
-
|
7
|
-
Background:
|
8
|
-
Given a file named "syntaxes_spec.rb" with:
|
9
|
-
"""ruby
|
10
|
-
describe "using the should syntax" do
|
11
|
-
specify { 3.should eq(3) }
|
12
|
-
specify { 3.should_not eq(4) }
|
13
|
-
specify { lambda { raise "boom" }.should raise_error("boom") }
|
14
|
-
specify { lambda { }.should_not raise_error }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe "using the expect syntax" do
|
18
|
-
specify { expect(3).to eq(3) }
|
19
|
-
specify { expect(3).not_to eq(4) }
|
20
|
-
specify { expect { raise "boom" }.to raise_error("boom") }
|
21
|
-
specify { expect { }.not_to raise_error }
|
22
|
-
end
|
23
|
-
"""
|
24
|
-
|
25
|
-
Scenario: Both syntaxes are available by default
|
26
|
-
When I run `rspec syntaxes_spec.rb`
|
27
|
-
Then the examples should all pass
|
28
|
-
|
29
|
-
Scenario: Disable should syntax
|
30
|
-
Given a file named "disable_should_syntax.rb" with:
|
31
|
-
"""ruby
|
32
|
-
RSpec.configure do |config|
|
33
|
-
config.expect_with :rspec do |c|
|
34
|
-
c.syntax = :expect
|
35
|
-
end
|
36
|
-
end
|
37
|
-
"""
|
38
|
-
When I run `rspec disable_should_syntax.rb syntaxes_spec.rb`
|
39
|
-
Then the output should contain all of these:
|
40
|
-
| 8 examples, 4 failures |
|
41
|
-
| undefined method `should' |
|
42
|
-
|
43
|
-
Scenario: Disable expect syntax
|
44
|
-
Given a file named "disable_expect_syntax.rb" with:
|
45
|
-
"""ruby
|
46
|
-
RSpec.configure do |config|
|
47
|
-
config.expect_with :rspec do |c|
|
48
|
-
c.syntax = :should
|
49
|
-
end
|
50
|
-
config.mock_with :rspec do |c|
|
51
|
-
c.syntax = :should
|
52
|
-
end
|
53
|
-
end
|
54
|
-
"""
|
55
|
-
When I run `rspec disable_expect_syntax.rb syntaxes_spec.rb`
|
56
|
-
Then the output should contain all of these:
|
57
|
-
| 8 examples, 4 failures |
|
58
|
-
| undefined method `expect' |
|
59
|
-
|
60
|
-
Scenario: Explicitly enable both syntaxes
|
61
|
-
Given a file named "enable_both_syntaxes.rb" with:
|
62
|
-
"""ruby
|
63
|
-
RSpec.configure do |config|
|
64
|
-
config.expect_with :rspec do |c|
|
65
|
-
c.syntax = [:should, :expect]
|
66
|
-
end
|
67
|
-
end
|
68
|
-
"""
|
69
|
-
When I run `rspec enable_both_syntaxes.rb syntaxes_spec.rb`
|
70
|
-
Then the examples should all pass
|
71
|
-
|
@@ -1,44 +0,0 @@
|
|
1
|
-
Feature: Minitest integration
|
2
|
-
|
3
|
-
rspec-expectations is a stand-alone gem that can be used without the rest of
|
4
|
-
RSpec. If you like minitest as your test runner, but prefer RSpec's
|
5
|
-
approach to expressing expectations, you can have both.
|
6
|
-
|
7
|
-
To integrate rspec-expectations with minitest, require `rspec/expectations/minitest_integration`.
|
8
|
-
|
9
|
-
Scenario: use rspec/expectations with minitest
|
10
|
-
Given a file named "rspec_expectations_test.rb" with:
|
11
|
-
"""ruby
|
12
|
-
require 'minitest/autorun'
|
13
|
-
require 'rspec/expectations/minitest_integration'
|
14
|
-
|
15
|
-
class RSpecExpectationsTest < Minitest::Test
|
16
|
-
RSpec::Matchers.define :be_an_integer do
|
17
|
-
match { |actual| Integer === actual }
|
18
|
-
end
|
19
|
-
|
20
|
-
def be_an_int
|
21
|
-
# This is actually an internal rspec-expectations API, but is used
|
22
|
-
# here to demonstrate that deprecation warnings from within
|
23
|
-
# rspec-expectations work correcty without depending on rspec-core
|
24
|
-
RSpec.deprecate(:be_an_int, :replacement => :be_an_integer)
|
25
|
-
be_an_integer
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_passing_expectation
|
29
|
-
expect(1 + 3).to eq 4
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_failing_expectation
|
33
|
-
expect([1, 2]).to be_empty
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_custom_matcher_with_deprecation_warning
|
37
|
-
expect(1).to be_an_int
|
38
|
-
end
|
39
|
-
end
|
40
|
-
"""
|
41
|
-
When I run `ruby rspec_expectations_test.rb`
|
42
|
-
Then the output should contain "3 runs, 3 assertions, 1 failures, 0 errors"
|
43
|
-
And the output should contain "expected empty? to return true, got false"
|
44
|
-
And the output should contain "be_an_int is deprecated"
|
data/lib/rspec-expectations.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require "rspec/expectations"
|
@@ -1,141 +0,0 @@
|
|
1
|
-
require 'diff/lcs'
|
2
|
-
require "rspec/expectations/encoded_string"
|
3
|
-
require "rspec/expectations/differ"
|
4
|
-
require 'diff/lcs/hunk'
|
5
|
-
require 'pp'
|
6
|
-
|
7
|
-
module RSpec
|
8
|
-
module Expectations
|
9
|
-
class DiffPresenter
|
10
|
-
def diff_as_string(actual, expected)
|
11
|
-
@encoding = pick_encoding actual, expected
|
12
|
-
|
13
|
-
@actual = EncodedString.new(actual, @encoding)
|
14
|
-
@expected = EncodedString.new(expected, @encoding)
|
15
|
-
|
16
|
-
output = EncodedString.new("\n", @encoding)
|
17
|
-
|
18
|
-
hunks.each_cons(2) do |prev_hunk, current_hunk|
|
19
|
-
begin
|
20
|
-
if current_hunk.overlaps?(prev_hunk)
|
21
|
-
add_old_hunk_to_hunk(current_hunk, prev_hunk)
|
22
|
-
else
|
23
|
-
add_to_output(output, prev_hunk.diff(format).to_s)
|
24
|
-
end
|
25
|
-
ensure
|
26
|
-
add_to_output(output, "\n")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
if hunks.last
|
31
|
-
finalize_output(output, hunks.last.diff(format).to_s)
|
32
|
-
end
|
33
|
-
|
34
|
-
color_diff output
|
35
|
-
rescue Encoding::CompatibilityError
|
36
|
-
handle_encoding_errors
|
37
|
-
end
|
38
|
-
|
39
|
-
def diff_as_object(actual, expected)
|
40
|
-
actual_as_string = object_to_string(actual)
|
41
|
-
expected_as_string = object_to_string(expected)
|
42
|
-
diff_as_string(actual_as_string, expected_as_string)
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def hunks
|
48
|
-
@hunks ||= Differ.new(@actual, @expected).hunks
|
49
|
-
end
|
50
|
-
|
51
|
-
def finalize_output(output, final_line)
|
52
|
-
add_to_output(output, final_line)
|
53
|
-
add_to_output(output, "\n")
|
54
|
-
end
|
55
|
-
|
56
|
-
def add_to_output(output, string)
|
57
|
-
output << string
|
58
|
-
end
|
59
|
-
|
60
|
-
def add_old_hunk_to_hunk(hunk, oldhunk)
|
61
|
-
hunk.merge(oldhunk)
|
62
|
-
end
|
63
|
-
|
64
|
-
def format
|
65
|
-
:unified
|
66
|
-
end
|
67
|
-
|
68
|
-
def color(text, color_code)
|
69
|
-
"\e[#{color_code}m#{text}\e[0m"
|
70
|
-
end
|
71
|
-
|
72
|
-
def red(text)
|
73
|
-
color(text, 31)
|
74
|
-
end
|
75
|
-
|
76
|
-
def green(text)
|
77
|
-
color(text, 32)
|
78
|
-
end
|
79
|
-
|
80
|
-
def blue(text)
|
81
|
-
color(text, 34)
|
82
|
-
end
|
83
|
-
|
84
|
-
def normal(text)
|
85
|
-
color(text, 0)
|
86
|
-
end
|
87
|
-
|
88
|
-
def color_diff(diff)
|
89
|
-
return diff unless RSpec::Matchers.configuration.color?
|
90
|
-
|
91
|
-
diff.lines.map { |line|
|
92
|
-
case line[0].chr
|
93
|
-
when "+"
|
94
|
-
green line
|
95
|
-
when "-"
|
96
|
-
red line
|
97
|
-
when "@"
|
98
|
-
line[1].chr == "@" ? blue(line) : normal(line)
|
99
|
-
else
|
100
|
-
normal(line)
|
101
|
-
end
|
102
|
-
}.join
|
103
|
-
end
|
104
|
-
|
105
|
-
def object_to_string(object)
|
106
|
-
object = Matchers::Composable.surface_descriptions_in(object)
|
107
|
-
case object
|
108
|
-
when Hash
|
109
|
-
object.keys.sort_by { |k| k.to_s }.map do |key|
|
110
|
-
pp_key = PP.singleline_pp(key, "")
|
111
|
-
pp_value = PP.singleline_pp(object[key], "")
|
112
|
-
|
113
|
-
"#{pp_key} => #{pp_value},"
|
114
|
-
end.join("\n")
|
115
|
-
when String
|
116
|
-
object =~ /\n/ ? object : object.inspect
|
117
|
-
else
|
118
|
-
PP.pp(object,"")
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
if String.method_defined?(:encoding)
|
123
|
-
def pick_encoding(source_a, source_b)
|
124
|
-
Encoding.compatible?(source_a, source_b) || Encoding.default_external
|
125
|
-
end
|
126
|
-
else
|
127
|
-
def pick_encoding(source_a, source_b)
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
def handle_encoding_errors
|
132
|
-
if @actual.source_encoding != @expected.source_encoding
|
133
|
-
"Could not produce a diff because the encoding of the actual string (#{@actual.source_encoding}) "+
|
134
|
-
"differs from the encoding of the expected string (#{@expected.source_encoding})"
|
135
|
-
else
|
136
|
-
"Could not produce a diff because of the encoding of the string (#{@expected.source_encoding})"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|