Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add built-in matchers to /rspec-expectations

  • Loading branch information...
commit eaa5534f57445793b151c8e75d5638ccc651ef22 1 parent 5a3b1ac
@dchelimsky dchelimsky authored
Showing with 110 additions and 17 deletions.
  1. +8 −11 content/rspec-core/index.page
  2. +102 −6 content/rspec-expectations/index.page
View
19 content/rspec-core/index.page
@@ -1,10 +1,10 @@
----
+---
title: rspec-core
order: 1
filter:
- erb
- markdown
----
+---
## rspec-core
@@ -26,7 +26,7 @@ an _example_ within that group. You can run this spec with the `rspec` command,
like this:
<% coderay :lang => 'shell' do -%>
-$ rspec account_spec.rb
+$ rspec account_spec.rb
.
1 example, 0 failures
@@ -48,9 +48,6 @@ This is a great way to quickly scan the docstrings of all the examples,
encouraging you to make them readable, and exposing which behaviors you have
and have not specified at a glance.
-See ??? for more information on built-in formatters and extensions that other
-folks have published in their own gems, as well as how to write your own.
-
## nested groups
An example group can contain any number of examples, and can also be nested
@@ -113,7 +110,7 @@ each example or only once per group:
after(:each) do
# this is after each example
end
-
+
after do
# :each is the default, so this is the same as after(:each)
end
@@ -122,7 +119,7 @@ each example or only once per group:
# this is run once and only once, after all of the examples and after any
# after(:each) blocks in this group.
end
-
+
end
<% end -%>
@@ -158,7 +155,7 @@ describe "Search page" do
it "should find all contacts" do
# ...
end
-
+
after(:all) do
@browser.kill! rescue nil
end
@@ -170,7 +167,7 @@ end
Sometimes you have some generic code you want to run before or after every
single one of your examples. Such global before and after blocks can be defined
in the RSpec configuration, which typically lives in a spec_helper.rb file that
-is required from other spec files. Example:
+is required from other spec files. Example:
<% coderay do -%>
RSpec.configure do |config|
@@ -227,7 +224,7 @@ You can write helper methods directly within an Example Group:
it "..." do
helper_method
end
-
+
def helper_method
...
end
View
108 content/rspec-expectations/index.page
@@ -1,13 +1,109 @@
----
+---
title: rspec-expectations
order: 2
filter:
- erb
- - textile
----
+ - markdown
+---
-h2. RSpec::Expectations and RSpec::Matchers
+## rspec-expectations
-rspec-expectations defines <code>should</code> and <code>should_not</code> on every object in the system. These methods allow
+rspec-expectations defines <code>should</code> and <code>should_not</code> on
+every object in the system. Here is a list of all the built-in matchers
+provided by rspec-expectations. See
+[RSpec::Expectations](http://rdoc.info/gems/rspec-expectations/RSpec/Expectations)
+and [RSpec::Matchers](http://rdoc.info/gems/rspec-expectations/RSpec/Matchers)
+for more information.
-See "RSpec::Expectations":http://rdoc.info/gems/rspec-expectations/RSpec/Expectations and "RSpec::Matchers":http://rdoc.info/gems/rspec-expectations/RSpec/Matchers for more information.
+## built in matchers
+
+### Object eqivalence
+
+<% coderay lang='ruby' do %>
+actual.should eq(expected) # passes if actual == expected
+actual.should == expected # passes if actual == expected
+actual.should eql(expected) # passes if actual.eql?(expected)
+<% end %>
+
+### Object identity
+
+<% coderay lang='ruby' do %>
+actual.should equal(expected) # passes if actual.equal?(expected)
+actual.should be(expected) # passes if actual.equal?(expected)
+<% end %>
+
+
+### Comparisons
+
+<% coderay lang='ruby' do %>
+actual.should be > expected
+actual.should be >= expected
+actual.should be <= expected
+actual.should be < expected
+actual.should =~ /expression/
+actual.should match(/expression/)
+actual.should be_within(delta).of(expected)
+<% end %>
+
+### Types/classes
+
+<% coderay lang='ruby' do %>
+actual.should be_instance_of(expected)
+actual.should be_kind_of(expected)
+<% end %>
+
+### Truthiness
+
+<% coderay lang='ruby' do %>
+actual.should be_true # passes if actual is truthy (not nil or false)
+actual.should be_false # passes if actual is falsy (nil or false)
+actual.should be_nil # passes if actual is nil
+<% end %>
+
+### Expecting errors
+
+<% coderay lang='ruby' do %>
+expect { ... }.to raise_error
+expect { ... }.to raise_error(ErrorClass)
+expect { ... }.to raise_error("message")
+expect { ... }.to raise_error(ErrorClass, "message")
+<% end %>
+
+### Expecting throws
+
+<% coderay lang='ruby' do %>
+expect { ... }.to throw_symbol
+expect { ... }.to throw_symbol(:symbol)
+expect { ... }.to throw_symbol(:symbol, 'value')
+<% end %>
+
+### Predicate matchers
+
+<% coderay lang='ruby' do %>
+actual.should be_xxx # passes if actual.xxx?
+actual.should have_xxx(:arg) # passes if actual.has_xxx?(:arg)
+
+# examples
+
+[].should be_empty # passes because [].empty? returns true
+{ :a => 1 }.should have_key(:a) # passes because the hash has the key :a
+<% end %>
+
+### Collection membership
+
+<% coderay lang='ruby' do %>
+actual.should include(expected)
+
+# examples
+
+[1,2,3].should include(1)
+[1,2,3].should include(1, 2)
+{:a => 'b'}.should include(:a => 'b')
+"this string".should include("is str")
+<% end %>
+
+### Ranges (Ruby >= 1.9)
+
+<% coderay lang='ruby' do %>
+(1..10).should cover(3)
+<% end %>
Please sign in to comment.
Something went wrong with that request. Please try again.