rspec-expectations 2.0.0.beta.22 → 2.6.0
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.
- data/.gitignore +1 -1
- data/.travis.yml +7 -0
- data/Gemfile +35 -13
- data/Guardfile +5 -0
- data/License.txt +1 -1
- data/README.md +43 -0
- data/Rakefile +51 -9
- data/cucumber.yml +9 -2
- data/features/.nav +29 -0
- data/features/Changelog.md +101 -0
- data/features/README.markdown +45 -8
- data/features/built_in_matchers/README.md +71 -0
- data/features/built_in_matchers/be.feature +135 -0
- data/features/built_in_matchers/be_within.feature +43 -0
- data/features/built_in_matchers/cover.feature +45 -0
- data/features/{matchers → built_in_matchers}/equality.feature +16 -13
- data/features/built_in_matchers/exist.feature +43 -0
- data/features/built_in_matchers/expect_change.feature +59 -0
- data/features/built_in_matchers/expect_error.feature +105 -0
- data/features/built_in_matchers/have.feature +103 -0
- data/features/built_in_matchers/include.feature +121 -0
- data/features/built_in_matchers/match.feature +50 -0
- data/features/built_in_matchers/operators.feature +221 -0
- data/features/built_in_matchers/predicates.feature +128 -0
- data/features/built_in_matchers/respond_to.feature +78 -0
- data/features/built_in_matchers/satisfy.feature +31 -0
- data/features/built_in_matchers/throw_symbol.feature +85 -0
- data/features/built_in_matchers/types.feature +114 -0
- data/features/{matchers → custom_matchers}/access_running_example.feature +2 -2
- data/features/{matchers → custom_matchers}/define_diffable_matcher.feature +1 -1
- data/features/{matchers → custom_matchers}/define_matcher.feature +91 -9
- data/features/{matchers → custom_matchers}/define_matcher_outside_rspec.feature +1 -1
- data/features/{matchers → custom_matchers}/define_matcher_with_fluent_interface.feature +8 -11
- data/features/customized_message.feature +22 -0
- data/features/{expectations/diffing.feature → diffing.feature} +16 -16
- data/features/{expectations/implicit_docstrings.feature → implicit_docstrings.feature} +4 -4
- data/features/step_definitions/additional_cli_steps.rb +22 -0
- data/features/support/env.rb +5 -1
- data/features/test_frameworks/test_unit.feature +46 -0
- data/lib/rspec/expectations/backward_compatibility.rb +22 -1
- data/lib/rspec/expectations/deprecation.rb +36 -0
- data/lib/rspec/expectations/extensions.rb +0 -1
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/expectations.rb +2 -1
- data/lib/rspec/matchers/be.rb +4 -4
- data/lib/rspec/matchers/be_close.rb +2 -17
- data/lib/rspec/matchers/be_within.rb +40 -0
- data/lib/rspec/matchers/block_aliases.rb +19 -0
- data/lib/rspec/matchers/change.rb +74 -49
- data/lib/rspec/matchers/cover.rb +35 -0
- data/lib/rspec/matchers/exist.rb +13 -3
- data/lib/rspec/matchers/has.rb +15 -11
- data/lib/rspec/matchers/have.rb +5 -5
- data/lib/rspec/matchers/include.rb +14 -5
- data/lib/rspec/matchers/matcher.rb +39 -13
- data/lib/rspec/matchers/method_missing.rb +6 -3
- data/lib/rspec/matchers/operator_matcher.rb +12 -3
- data/lib/rspec/matchers/respond_to.rb +23 -9
- data/lib/rspec/matchers/satisfy.rb +4 -0
- data/lib/rspec/matchers/throw_symbol.rb +43 -26
- data/lib/rspec/matchers.rb +15 -3
- data/rspec-expectations.gemspec +2 -6
- data/spec/rspec/matchers/be_close_spec.rb +11 -39
- data/spec/rspec/matchers/be_spec.rb +8 -8
- data/spec/rspec/matchers/be_within_spec.rb +64 -0
- data/spec/rspec/matchers/change_spec.rb +88 -9
- data/spec/rspec/matchers/cover_spec.rb +65 -0
- data/spec/rspec/matchers/description_generation_spec.rb +41 -25
- data/spec/rspec/matchers/exist_spec.rb +90 -51
- data/spec/rspec/matchers/has_spec.rb +2 -2
- data/spec/rspec/matchers/have_spec.rb +291 -291
- data/spec/rspec/matchers/include_spec.rb +318 -65
- data/spec/rspec/matchers/matcher_spec.rb +91 -0
- data/spec/rspec/matchers/matchers_spec.rb +29 -0
- data/spec/rspec/matchers/method_missing_spec.rb +23 -0
- data/spec/rspec/matchers/operator_matcher_spec.rb +36 -10
- data/spec/rspec/matchers/respond_to_spec.rb +177 -1
- data/spec/rspec/matchers/satisfy_spec.rb +4 -0
- data/spec/rspec/matchers/throw_symbol_spec.rb +27 -10
- data/spec/spec_helper.rb +10 -35
- data/spec/support/classes.rb +1 -1
- data/spec/support/matchers.rb +22 -0
- data/spec/support/ruby_version.rb +10 -0
- metadata +95 -114
- data/History.md +0 -16
- data/README.markdown +0 -23
- data/features/expectations/attribute_of_subject.feature +0 -19
- data/features/expectations/customized_message.feature +0 -54
- data/features/matchers/expect_change.feature +0 -65
- data/features/matchers/expect_error.feature +0 -44
- data/lib/rspec/expectations/extensions/rspec/core/example_group.rb +0 -19
- data/spec/suite.rb +0 -1
- /data/{Upgrade.markdown → features/Upgrade.md} +0 -0
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
|
@@ -1,18 +1,40 @@
|
|
|
1
1
|
source "http://rubygems.org"
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
gem
|
|
8
|
-
|
|
9
|
-
gem
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
### rspec libs
|
|
4
|
+
%w[rspec rspec-core rspec-expectations rspec-mocks].each do |lib|
|
|
5
|
+
library_path = File.expand_path("../../#{lib}", __FILE__)
|
|
6
|
+
if File.exist?(library_path)
|
|
7
|
+
gem lib, :path => library_path
|
|
8
|
+
else
|
|
9
|
+
gem lib, :git => "git://github.com/rspec/#{lib}.git"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
### dev dependencies
|
|
14
|
+
gem "rake", "0.8.7"
|
|
15
|
+
gem "cucumber", "~> 0.10.2"
|
|
16
|
+
gem "aruba", "~> 0.3.6"
|
|
17
|
+
gem "rcov", "0.9.9", :platforms => :mri
|
|
18
|
+
gem "relish", "0.2.0"
|
|
19
|
+
gem "guard-rspec", "0.1.9"
|
|
20
|
+
gem "growl", "1.0.3"
|
|
21
|
+
gem "nokogiri", "1.4.4"
|
|
22
|
+
|
|
23
|
+
platforms :mri_18 do
|
|
17
24
|
gem 'ruby-debug'
|
|
18
25
|
end
|
|
26
|
+
|
|
27
|
+
platforms :mri_19 do
|
|
28
|
+
gem 'linecache19', '0.5.11' # 0.5.12 cannot install on 1.9.1, and 0.5.11 appears to work with both 1.9.1 & 1.9.2
|
|
29
|
+
gem 'ruby-debug19'
|
|
30
|
+
gem 'ruby-debug-base19', RUBY_VERSION == '1.9.1' ? '0.11.23' : '~> 0.11.24'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
platforms :mri_18, :mri_19 do
|
|
34
|
+
gem "rb-fsevent", "~> 0.3.9"
|
|
35
|
+
gem "ruby-prof", "~> 0.9.2"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
platforms :jruby do
|
|
39
|
+
gem "jruby-openssl"
|
|
40
|
+
end
|
data/Guardfile
ADDED
data/License.txt
CHANGED
data/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# RSpec Expectations
|
|
2
|
+
|
|
3
|
+
rspec-expectations adds `should` and `should_not` to every object and includes
|
|
4
|
+
RSpec::Matchers, a library of standard matchers.
|
|
5
|
+
|
|
6
|
+
[](http://travis-ci.org/rspec/rspec-expectations)
|
|
7
|
+
|
|
8
|
+
## Documentation
|
|
9
|
+
|
|
10
|
+
The [Cucumber features](http://relishapp.com/rspec/rspec-expectations)
|
|
11
|
+
are the most comprehensive and up-to-date docs for end-users.
|
|
12
|
+
|
|
13
|
+
The [RDoc](http://rubydoc.info/gems/rspec-expectations/2.3.0/frames) provides
|
|
14
|
+
additional information for contributors and/or extenders.
|
|
15
|
+
|
|
16
|
+
All of the documentation is open source and a work in progress. If you find it
|
|
17
|
+
lacking or confusing, you can help improve it by submitting requests and
|
|
18
|
+
patches to the [rspec-expectations issue
|
|
19
|
+
tracker](https://github.com/rspec/rspec-expectations/issues).
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
gem install rspec # for rspec-core, rspec-expectations, rspec-mocks
|
|
24
|
+
gem install rspec-expecctations # for rspec-expectations only
|
|
25
|
+
|
|
26
|
+
## Matchers
|
|
27
|
+
|
|
28
|
+
Matchers are objects used to compose expectations:
|
|
29
|
+
|
|
30
|
+
result.should eq("this value")
|
|
31
|
+
|
|
32
|
+
In that example, `eq("this value")` returns a `Matcher` object that
|
|
33
|
+
compares the actual `result` to the expected `"this value"`.
|
|
34
|
+
|
|
35
|
+
## Contribute
|
|
36
|
+
|
|
37
|
+
See [http://github.com/rspec/rspec-dev](http://github.com/rspec/rspec-dev)
|
|
38
|
+
|
|
39
|
+
## Also see
|
|
40
|
+
|
|
41
|
+
* [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
|
|
42
|
+
* [http://github.com/rspec/rspec-core](http://github.com/rspec/rspec-core)
|
|
43
|
+
* [http://github.com/rspec/rspec-mocks](http://github.com/rspec/rspec-mocks)
|
data/Rakefile
CHANGED
|
@@ -5,20 +5,56 @@ Bundler::GemHelper.install_tasks
|
|
|
5
5
|
require 'rake'
|
|
6
6
|
require 'rake/rdoctask'
|
|
7
7
|
require 'rspec/core/rake_task'
|
|
8
|
-
require '
|
|
8
|
+
require 'rspec/expectations/version'
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
begin
|
|
11
|
+
require 'cucumber/rake/task'
|
|
11
12
|
|
|
12
|
-
class Cucumber::Rake::Task::ForkedCucumberRunner
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
class Cucumber::Rake::Task::ForkedCucumberRunner
|
|
14
|
+
# When cucumber shells out, we still need it to run in the context of our
|
|
15
|
+
# bundle.
|
|
16
|
+
def run
|
|
17
|
+
sh "bundle exec #{RUBY} " + args.join(" ")
|
|
18
|
+
end
|
|
17
19
|
end
|
|
20
|
+
|
|
21
|
+
Cucumber::Rake::Task.new(:cucumber)
|
|
22
|
+
|
|
23
|
+
namespace :cucumber do
|
|
24
|
+
desc "Run cucumber features using rcov"
|
|
25
|
+
Cucumber::Rake::Task.new :rcov => :cleanup_rcov_files do |t|
|
|
26
|
+
t.cucumber_opts = %w{--format progress}
|
|
27
|
+
t.rcov = true
|
|
28
|
+
t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
|
|
29
|
+
t.rcov_opts << %[--text-report --sort coverage --aggregate coverage.data]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
rescue LoadError => e
|
|
34
|
+
puts "unable to load cucumber, some tasks unavailable"
|
|
35
|
+
task :cucumber do
|
|
36
|
+
#no-op
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
task :cleanup_rcov_files do
|
|
42
|
+
rm_rf 'coverage.data'
|
|
18
43
|
end
|
|
19
44
|
|
|
20
|
-
|
|
21
|
-
|
|
45
|
+
desc "Run all examples"
|
|
46
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
47
|
+
t.rspec_opts = %w[--color]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
namespace :spec do
|
|
52
|
+
desc "Run all examples using rcov"
|
|
53
|
+
RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
|
|
54
|
+
t.rcov = true
|
|
55
|
+
t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
|
|
56
|
+
t.rcov_opts << %[--text-report --sort coverage --no-html --aggregate coverage.data]
|
|
57
|
+
end
|
|
22
58
|
end
|
|
23
59
|
|
|
24
60
|
task :default => [:spec, :cucumber]
|
|
@@ -30,6 +66,12 @@ Rake::RDocTask.new do |rdoc|
|
|
|
30
66
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
31
67
|
end
|
|
32
68
|
|
|
69
|
+
desc "Push docs/cukes to relishapp using the relish-client-gem"
|
|
70
|
+
task :relish, :version do |t, args|
|
|
71
|
+
raise "rake relish[VERSION]" unless args[:version]
|
|
72
|
+
sh "relish push rspec/rspec-expectations:#{args[:version]}"
|
|
73
|
+
end
|
|
74
|
+
|
|
33
75
|
task :clobber do
|
|
34
76
|
rm_rf 'doc'
|
|
35
77
|
rm_rf 'pkg'
|
data/cucumber.yml
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
<%
|
|
2
|
+
def tags(tag)
|
|
3
|
+
tags = [tag]
|
|
4
|
+
tags << "~@ruby-1.9" if RUBY_VERSION.to_f < 1.9
|
|
5
|
+
tags.join(" --tags ")
|
|
6
|
+
end
|
|
7
|
+
%>
|
|
3
8
|
|
|
9
|
+
default: --require features --tags <%= tags("~@wip") %> --format progress
|
|
10
|
+
wip: --require features --tags <%= tags("@wip:3") --wip features
|
data/features/.nav
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
- Upgrade.md
|
|
2
|
+
- Changelog.md
|
|
3
|
+
- customized_message.feature
|
|
4
|
+
- diffing.feature
|
|
5
|
+
- implicit_docstrings.feature
|
|
6
|
+
- built_in_matchers:
|
|
7
|
+
- be.feature
|
|
8
|
+
- be_within.feature
|
|
9
|
+
- equality.feature
|
|
10
|
+
- exist.feature
|
|
11
|
+
- expect_change.feature
|
|
12
|
+
- expect_error.feature
|
|
13
|
+
- have.feature
|
|
14
|
+
- include.feature
|
|
15
|
+
- match.feature
|
|
16
|
+
- operators.feature
|
|
17
|
+
- predicates.feature
|
|
18
|
+
- respond_to.feature
|
|
19
|
+
- satisfy.feature
|
|
20
|
+
- throw_symbol.feature
|
|
21
|
+
- types.feature
|
|
22
|
+
- custom_matchers:
|
|
23
|
+
- define_matcher.feature
|
|
24
|
+
- define_diffable_matcher.feature
|
|
25
|
+
- define_matcher_with_fluent_interface.feature
|
|
26
|
+
- access_running_example.feature
|
|
27
|
+
- define_matcher_outside_rspec.feature
|
|
28
|
+
- test_frameworks:
|
|
29
|
+
- test_unit.feature
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
### 2.6.0 / 2011-05-12
|
|
2
|
+
|
|
3
|
+
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.5.0...v2.6.0)
|
|
4
|
+
|
|
5
|
+
* Enhancments
|
|
6
|
+
* `change` matcher accepts Regexps (Robert Davis)
|
|
7
|
+
* better descriptions for have_xxx matchers (Magnus Bergmark)
|
|
8
|
+
* range.should cover(*values) (Anders Furseth)
|
|
9
|
+
|
|
10
|
+
* Bug fixes
|
|
11
|
+
* Removed non-ascii characters that were choking rcov (Geoffrey Byers)
|
|
12
|
+
* change matcher dups arrays and hashes so their before/after states can be
|
|
13
|
+
compared correctly.
|
|
14
|
+
* Fix the order of inclusion of RSpec::Matchers in
|
|
15
|
+
Test::Unit::TestCase and MiniTest::Unit::TestCase to prevent a
|
|
16
|
+
SystemStackError (Myron Marston)
|
|
17
|
+
|
|
18
|
+
### 2.5.0 / 2011-02-05
|
|
19
|
+
|
|
20
|
+
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.4.0...v2.5.0)
|
|
21
|
+
|
|
22
|
+
* Enhancements
|
|
23
|
+
* `should exist` works with `exist?` or `exists?` (Myron Marston)
|
|
24
|
+
* `expect { ... }.not_to do_something` (in addition to `to_not`)
|
|
25
|
+
|
|
26
|
+
* Documentation
|
|
27
|
+
* improved docs for raise_error matcher (James Almond)
|
|
28
|
+
|
|
29
|
+
### 2.4.0 / 2011-01-02
|
|
30
|
+
|
|
31
|
+
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.3.0...v2.4.0)
|
|
32
|
+
|
|
33
|
+
No functional changes in this release, which was made to align with the
|
|
34
|
+
rspec-core-2.4.0 release.
|
|
35
|
+
|
|
36
|
+
* Enhancements
|
|
37
|
+
* improved RDoc for change matcher (Jo Liss)
|
|
38
|
+
|
|
39
|
+
### 2.3.0 / 2010-12-12
|
|
40
|
+
|
|
41
|
+
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.2.1...v2.3.0)
|
|
42
|
+
|
|
43
|
+
* Enhancements
|
|
44
|
+
* diff strings when include matcher fails (Mike Sassak)
|
|
45
|
+
|
|
46
|
+
### 2.2.0 / 2010-11-28
|
|
47
|
+
|
|
48
|
+
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.1.0...v2.2.0)
|
|
49
|
+
|
|
50
|
+
### 2.1.0 / 2010-11-07
|
|
51
|
+
|
|
52
|
+
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.1...v2.1.0)
|
|
53
|
+
|
|
54
|
+
* Enhancements
|
|
55
|
+
* be_within(delta).of(expected) matcher (Myron Marston)
|
|
56
|
+
* Lots of new Cucumber features (Myron Marston)
|
|
57
|
+
* Raise error if you try "should != expected" on Ruby-1.9 (Myron Marston)
|
|
58
|
+
* Improved failure messages from throw_symbol (Myron Marston)
|
|
59
|
+
|
|
60
|
+
* Bug fixes
|
|
61
|
+
* Eliminate hard dependency on RSpec::Core (Myron Marston)
|
|
62
|
+
* have_matcher - use pluralize only when ActiveSupport inflections are indeed
|
|
63
|
+
defined (Josep M Bach)
|
|
64
|
+
* throw_symbol matcher no longer swallows exceptions (Myron Marston)
|
|
65
|
+
* fix matcher chaining to avoid name collisions (Myron Marston)
|
|
66
|
+
|
|
67
|
+
### 2.0.0 / 2010-10-10
|
|
68
|
+
|
|
69
|
+
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.rc...v2.0.0)
|
|
70
|
+
|
|
71
|
+
* Enhancements
|
|
72
|
+
* Add match_for_should_not method to matcher DSL (Myron Marston)
|
|
73
|
+
|
|
74
|
+
* Bug fixes
|
|
75
|
+
* respond_to matcher works correctly with should_not with multiple methods (Myron Marston)
|
|
76
|
+
* include matcher works correctly with should_not with multiple values (Myron Marston)
|
|
77
|
+
|
|
78
|
+
### 2.0.0.rc / 2010-10-05
|
|
79
|
+
|
|
80
|
+
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.beta.22...v2.0.0.rc)
|
|
81
|
+
|
|
82
|
+
* Enhancements
|
|
83
|
+
* require 'rspec/expectations' in a T::U or MiniUnit suite (Josep M. Bach)
|
|
84
|
+
|
|
85
|
+
* Bug fixes
|
|
86
|
+
* change by 0 passes/fails correctly (Len Smith)
|
|
87
|
+
* Add description to satisfy matcher
|
|
88
|
+
|
|
89
|
+
### 2.0.0.beta.22 / 2010-09-12
|
|
90
|
+
|
|
91
|
+
[full changelog](http://github.com/rspec/rspec-expectations/compare/v2.0.0.beta.20...v2.0.0.beta.22)
|
|
92
|
+
|
|
93
|
+
* Enhancements
|
|
94
|
+
* diffing improvements
|
|
95
|
+
* diff multiline strings
|
|
96
|
+
* don't diff single line strings
|
|
97
|
+
* don't diff numbers (silly)
|
|
98
|
+
* diff regexp + multiline string
|
|
99
|
+
|
|
100
|
+
* Bug fixes
|
|
101
|
+
* should[_not] change now handles boolean values correctly
|
data/features/README.markdown
CHANGED
|
@@ -1,12 +1,49 @@
|
|
|
1
|
-
|
|
1
|
+
rspec-expectations is used to define expected outcomes.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
describe Account do
|
|
4
|
+
it "has a balance of zero when first created" do
|
|
5
|
+
Account.new.balance.should eq(Money.new(0))
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
## Basic structure
|
|
10
|
+
|
|
11
|
+
The basic structure of an rspec expectation is:
|
|
12
|
+
|
|
13
|
+
actual.should matcher(expected)
|
|
14
|
+
actual.should_not matcher(expected)
|
|
15
|
+
|
|
16
|
+
## `should` and `should_not`
|
|
17
|
+
|
|
18
|
+
`rspec-expectations` adds `should` and `should_not` to every object in
|
|
19
|
+
the system. These methods each accept a matcher as an argument. This allows
|
|
20
|
+
each matcher to work in a positive or negative mode:
|
|
21
|
+
|
|
22
|
+
5.should eq(5)
|
|
23
|
+
5.should_not eq(4)
|
|
24
|
+
|
|
25
|
+
## What is a matcher?
|
|
26
|
+
|
|
27
|
+
A Matcher is any object that responds to the following methods:
|
|
28
|
+
|
|
29
|
+
matches?(actual)
|
|
30
|
+
failure_message_for_should
|
|
31
|
+
|
|
32
|
+
These methods are also part of the matcher protocol, but are optional:
|
|
33
|
+
|
|
34
|
+
does_not_match?(actual)
|
|
35
|
+
failure_message_for_should_not
|
|
36
|
+
description
|
|
37
|
+
|
|
38
|
+
RSpec ships with a number of built-in matchers and a DSL for writing custom
|
|
39
|
+
matchers.
|
|
8
40
|
|
|
9
41
|
## Issues
|
|
10
42
|
|
|
11
|
-
|
|
12
|
-
|
|
43
|
+
The documentation for rspec-expectations is a work in progress. We'll be adding
|
|
44
|
+
Cucumber features over time, and clarifying existing ones. If you have
|
|
45
|
+
specific features you'd like to see added, find the existing documentation
|
|
46
|
+
incomplete or confusing, or, better yet, wish to write a missing Cucumber
|
|
47
|
+
feature yourself, please [submit an
|
|
48
|
+
issue](http://github.com/rspec/rspec-expectations/issues) or a [pull
|
|
49
|
+
request](http://github.com/rspec/rspec-expectations).
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
## Object identity
|
|
2
|
+
|
|
3
|
+
actual.should equal(expected) # passes if actual.equal?(expected)
|
|
4
|
+
|
|
5
|
+
## Object equivalence
|
|
6
|
+
|
|
7
|
+
actual.should == expected # passes if actual == expected
|
|
8
|
+
actual.should eql(expected) # passes if actual.eql?(expected)
|
|
9
|
+
|
|
10
|
+
## Optional APIs for identity/equivalence
|
|
11
|
+
|
|
12
|
+
actual.should eq(expected) # passes if actual == expected
|
|
13
|
+
actual.should be(expected) # passes if actual.equal?(expected)
|
|
14
|
+
|
|
15
|
+
## Comparisons
|
|
16
|
+
|
|
17
|
+
actual.should be > expected
|
|
18
|
+
actual.should be >= expected
|
|
19
|
+
actual.should be <= expected
|
|
20
|
+
actual.should be < expected
|
|
21
|
+
actual.should =~ /expression/
|
|
22
|
+
actual.should match(/expression/)
|
|
23
|
+
actual.should be_within(delta).of(expected)
|
|
24
|
+
|
|
25
|
+
## Types/classes
|
|
26
|
+
|
|
27
|
+
actual.should be_instance_of(expected)
|
|
28
|
+
actual.should be_kind_of(expected)
|
|
29
|
+
|
|
30
|
+
## Truthiness and existentialism
|
|
31
|
+
|
|
32
|
+
actual.should be_true # passes if actual is anything but nil or false
|
|
33
|
+
actual.should be_false # passes if actual is nil or false
|
|
34
|
+
actual.should be_nil # passes if actual is nil
|
|
35
|
+
actual.should be # passes if actual is not nil
|
|
36
|
+
|
|
37
|
+
## Expecting errors
|
|
38
|
+
|
|
39
|
+
expect { ... }.to raise_error
|
|
40
|
+
expect { ... }.to raise_error(ErrorClass)
|
|
41
|
+
expect { ... }.to raise_error("message")
|
|
42
|
+
expect { ... }.to raise_error(ErrorClass, "message")
|
|
43
|
+
|
|
44
|
+
## Expecting throws
|
|
45
|
+
|
|
46
|
+
expect { ... }.to throw_symbol
|
|
47
|
+
expect { ... }.to throw_symbol(:symbol)
|
|
48
|
+
expect { ... }.to throw_symbol(:symbol, 'value')
|
|
49
|
+
|
|
50
|
+
## Predicate matchers
|
|
51
|
+
|
|
52
|
+
actual.should be_xxx # passes if actual.xxx?
|
|
53
|
+
|
|
54
|
+
### Example
|
|
55
|
+
|
|
56
|
+
[].should be_empty # passes because [].empty? returns true
|
|
57
|
+
|
|
58
|
+
## Collection membership
|
|
59
|
+
|
|
60
|
+
actual.should include(expected)
|
|
61
|
+
|
|
62
|
+
### Examples
|
|
63
|
+
|
|
64
|
+
[1,2,3].should include(1)
|
|
65
|
+
[1,2,3].should include(1, 2)
|
|
66
|
+
{:a => 'b'}.should include(:a => 'b')
|
|
67
|
+
"this string".should include("is str")
|
|
68
|
+
|
|
69
|
+
## Ranges (1.9 only)
|
|
70
|
+
|
|
71
|
+
(1..10).should cover(3)
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
Feature: "be" matchers
|
|
2
|
+
|
|
3
|
+
There are several related "be" matchers:
|
|
4
|
+
|
|
5
|
+
obj.should be_true # passes if obj is truthy (not nil or false)
|
|
6
|
+
obj.should be_false # passes if obj is falsy (nil or false)
|
|
7
|
+
obj.should be_nil # passes if obj is nil
|
|
8
|
+
obj.should be # passes if obj is not nil
|
|
9
|
+
|
|
10
|
+
Scenario: be_true matcher
|
|
11
|
+
Given a file named "be_true_spec.rb" with:
|
|
12
|
+
"""
|
|
13
|
+
describe "be_true matcher" do
|
|
14
|
+
specify { true.should be_true }
|
|
15
|
+
specify { 7.should be_true }
|
|
16
|
+
specify { "foo".should be_true }
|
|
17
|
+
specify { nil.should_not be_true }
|
|
18
|
+
specify { false.should_not be_true }
|
|
19
|
+
|
|
20
|
+
# deliberate failures
|
|
21
|
+
specify { true.should_not be_true }
|
|
22
|
+
specify { 7.should_not be_true }
|
|
23
|
+
specify { "foo".should_not be_true }
|
|
24
|
+
specify { nil.should be_true }
|
|
25
|
+
specify { false.should be_true }
|
|
26
|
+
end
|
|
27
|
+
"""
|
|
28
|
+
When I run `rspec be_true_spec.rb`
|
|
29
|
+
Then the output should contain all of these:
|
|
30
|
+
| 10 examples, 5 failures |
|
|
31
|
+
| expected true not to be true |
|
|
32
|
+
| expected 7 not to be true |
|
|
33
|
+
| expected "foo" not to be true |
|
|
34
|
+
| expected nil to be true |
|
|
35
|
+
| expected false to be true |
|
|
36
|
+
|
|
37
|
+
Scenario: be_false matcher
|
|
38
|
+
Given a file named "be_false_spec.rb" with:
|
|
39
|
+
"""
|
|
40
|
+
describe "be_false matcher" do
|
|
41
|
+
specify { nil.should be_false }
|
|
42
|
+
specify { false.should be_false }
|
|
43
|
+
specify { true.should_not be_false }
|
|
44
|
+
specify { 7.should_not be_false }
|
|
45
|
+
specify { "foo".should_not be_false }
|
|
46
|
+
|
|
47
|
+
# deliberate failures
|
|
48
|
+
specify { nil.should_not be_false }
|
|
49
|
+
specify { false.should_not be_false }
|
|
50
|
+
specify { true.should be_false }
|
|
51
|
+
specify { 7.should be_false }
|
|
52
|
+
specify { "foo".should be_false }
|
|
53
|
+
end
|
|
54
|
+
"""
|
|
55
|
+
When I run `rspec be_false_spec.rb`
|
|
56
|
+
Then the output should contain all of these:
|
|
57
|
+
| 10 examples, 5 failures |
|
|
58
|
+
| expected nil not to be false |
|
|
59
|
+
| expected false not to be false |
|
|
60
|
+
| expected true to be false |
|
|
61
|
+
| expected 7 to be false |
|
|
62
|
+
| expected "foo" to be false |
|
|
63
|
+
|
|
64
|
+
Scenario: be_nil matcher
|
|
65
|
+
Given a file named "be_nil_spec.rb" with:
|
|
66
|
+
"""
|
|
67
|
+
describe "be_nil matcher" do
|
|
68
|
+
specify { nil.should be_nil }
|
|
69
|
+
specify { false.should_not be_nil }
|
|
70
|
+
specify { true.should_not be_nil }
|
|
71
|
+
specify { 7.should_not be_nil }
|
|
72
|
+
specify { "foo".should_not be_nil }
|
|
73
|
+
|
|
74
|
+
# deliberate failures
|
|
75
|
+
specify { nil.should_not be_nil }
|
|
76
|
+
specify { false.should be_nil }
|
|
77
|
+
specify { true.should be_nil }
|
|
78
|
+
specify { 7.should be_nil }
|
|
79
|
+
specify { "foo".should be_nil }
|
|
80
|
+
end
|
|
81
|
+
"""
|
|
82
|
+
When I run `rspec be_nil_spec.rb`
|
|
83
|
+
Then the output should contain "10 examples, 5 failures"
|
|
84
|
+
And the output should contain:
|
|
85
|
+
"""
|
|
86
|
+
expected: not nil
|
|
87
|
+
got: nil
|
|
88
|
+
"""
|
|
89
|
+
And the output should contain:
|
|
90
|
+
"""
|
|
91
|
+
expected: nil
|
|
92
|
+
got: false
|
|
93
|
+
"""
|
|
94
|
+
And the output should contain:
|
|
95
|
+
"""
|
|
96
|
+
expected: nil
|
|
97
|
+
got: true
|
|
98
|
+
"""
|
|
99
|
+
And the output should contain:
|
|
100
|
+
"""
|
|
101
|
+
expected: nil
|
|
102
|
+
got: 7
|
|
103
|
+
"""
|
|
104
|
+
And the output should contain:
|
|
105
|
+
"""
|
|
106
|
+
expected: nil
|
|
107
|
+
got: "foo"
|
|
108
|
+
"""
|
|
109
|
+
|
|
110
|
+
Scenario: be matcher
|
|
111
|
+
Given a file named "be_spec.rb" with:
|
|
112
|
+
"""
|
|
113
|
+
describe "be_matcher" do
|
|
114
|
+
specify { true.should be }
|
|
115
|
+
specify { 7.should be }
|
|
116
|
+
specify { "foo".should be }
|
|
117
|
+
specify { nil.should_not be }
|
|
118
|
+
specify { false.should_not be }
|
|
119
|
+
|
|
120
|
+
# deliberate failures
|
|
121
|
+
specify { true.should_not be }
|
|
122
|
+
specify { 7.should_not be }
|
|
123
|
+
specify { "foo".should_not be }
|
|
124
|
+
specify { nil.should be }
|
|
125
|
+
specify { false.should be }
|
|
126
|
+
end
|
|
127
|
+
"""
|
|
128
|
+
When I run `rspec be_spec.rb`
|
|
129
|
+
Then the output should contain all of these:
|
|
130
|
+
| 10 examples, 5 failures |
|
|
131
|
+
| expected true to evaluate to false |
|
|
132
|
+
| expected 7 to evaluate to false |
|
|
133
|
+
| expected "foo" to evaluate to false |
|
|
134
|
+
| expected nil to evaluate to true |
|
|
135
|
+
| expected false to evaluate to true |
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Feature: be_within matcher
|
|
2
|
+
|
|
3
|
+
Normal equality expectations do not work well for floating point values.
|
|
4
|
+
Consider this irb session:
|
|
5
|
+
|
|
6
|
+
> radius = 3
|
|
7
|
+
=> 3
|
|
8
|
+
> area_of_circle = radius * radius * Math::PI
|
|
9
|
+
=> 28.2743338823081
|
|
10
|
+
> area_of_circle == 28.2743338823081
|
|
11
|
+
=> false
|
|
12
|
+
|
|
13
|
+
Instead, you should use the be_within matcher to check that the value
|
|
14
|
+
is within a delta of your expected value:
|
|
15
|
+
|
|
16
|
+
area_of_circle.should be_within(0.1).of(28.3)
|
|
17
|
+
|
|
18
|
+
Note that the difference between the actual and expected values must be
|
|
19
|
+
smaller than your delta; if it is equal, the matcher will fail.
|
|
20
|
+
|
|
21
|
+
Scenario: basic usage
|
|
22
|
+
Given a file named "be_within_matcher_spec.rb" with:
|
|
23
|
+
"""
|
|
24
|
+
describe 27.5 do
|
|
25
|
+
it { should be_within(0.5).of(27.9) }
|
|
26
|
+
it { should be_within(0.5).of(27.1) }
|
|
27
|
+
it { should_not be_within(0.5).of(28) }
|
|
28
|
+
it { should_not be_within(0.5).of(27) }
|
|
29
|
+
|
|
30
|
+
# deliberate failures
|
|
31
|
+
it { should_not be_within(0.5).of(27.9) }
|
|
32
|
+
it { should_not be_within(0.5).of(27.1) }
|
|
33
|
+
it { should be_within(0.5).of(28) }
|
|
34
|
+
it { should be_within(0.5).of(27) }
|
|
35
|
+
end
|
|
36
|
+
"""
|
|
37
|
+
When I run `rspec be_within_matcher_spec.rb`
|
|
38
|
+
Then the output should contain all of these:
|
|
39
|
+
| 8 examples, 4 failures |
|
|
40
|
+
| expected 27.5 not to be within 0.5 of 27.9 |
|
|
41
|
+
| expected 27.5 not to be within 0.5 of 27.1 |
|
|
42
|
+
| expected 27.5 to be within 0.5 of 28 |
|
|
43
|
+
| expected 27.5 to be within 0.5 of 27 |
|