Skip to content

Commit

Permalink
Remove relative links from README, since they can't work correctly on
Browse files Browse the repository at this point in the history
github and rubydoc.info.

- Fixes #113.
  • Loading branch information
dchelimsky committed Jan 28, 2012
1 parent 65d3c4d commit 17325de
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 20 deletions.
15 changes: 2 additions & 13 deletions README.md
@@ -1,7 +1,7 @@
# RSpec Expectations

[RSpec::Expectations](../RSpec/Expectations) lets you express expected outcomes
on an object in an example.
RSpec::Expectations lets you express expected outcomes on an object in an
example.

account.balance.should eq(Money.new(37.42, :USD))

Expand Down Expand Up @@ -119,8 +119,6 @@ actual.should be_xxx # passes if actual.xxx?
actual.should have_xxx(:arg) # passes if actual.has_xxx?(:arg)
```

See [RSpec::Matchers](../RSpec/Matchers) for more about predicate matchers.

### Ranges (Ruby >= 1.9 only)

```ruby
Expand All @@ -142,15 +140,6 @@ actual.should include(expected)
"this string".should include("is str")
```

## Learn more

See [RSpec::Expectations](../RSpec/Expectations) for more information about
`should` and `should_not` and how they work.

See [RSpec::Matchers](../RSpec/Matchers) for more information about the
built-in matchers that ship with rspec-expectations, and how to write your own
custom matchers.

## Also see

* [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
Expand Down
27 changes: 27 additions & 0 deletions benchmarks/default_messages_as_methods_v_blocks.rb
@@ -0,0 +1,27 @@
require 'benchmark'
require 'rspec/expectations'

include RSpec::Expectations
include RSpec::Matchers

RSpec::Matchers.define :eq_using_dsl do |expected|
match do |actual|
actual == expected
end
end

n = 10000

Benchmark.benchmark do |bm|
3.times do
bm.report do
n.times do
eq_using_dsl(5).tap do |m|
m.description
m.failure_message_for_should
m.failure_message_for_should_not
end
end
end
end
end
25 changes: 18 additions & 7 deletions lib/rspec/matchers/matcher.rb
Expand Up @@ -20,12 +20,7 @@ def initialize(name, &declarations)
@diffable = false
@expected_exception, @rescued_exception = nil, nil
@match_for_should_not_block = nil

@messages = {
:description => lambda {"#{name_to_sentence}#{expected_to_sentence}"},
:failure_message_for_should => lambda {|actual| "expected #{actual.inspect} to #{name_to_sentence}#{expected_to_sentence}"},
:failure_message_for_should_not => lambda {|actual| "expected #{actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}"}
}
@messages = {}
end

PERSISENT_INSTANCE_VARIABLES = [
Expand Down Expand Up @@ -273,7 +268,23 @@ def cache(key, &block)
end

def call_cached(key)
@messages[key].arity == 1 ? @messages[key].call(@actual) : @messages[key].call
if @messages.has_key?(key)
@messages[key].arity == 1 ? @messages[key].call(@actual) : @messages[key].call
else
send("default_#{key}")
end
end

def default_description
"#{name_to_sentence}#{expected_to_sentence}"
end

def default_failure_message_for_should
"expected #{actual.inspect} to #{name_to_sentence}#{expected_to_sentence}"
end

def default_failure_message_for_should_not
"expected #{actual.inspect} not to #{name_to_sentence}#{expected_to_sentence}"
end

unless method_defined?(:singleton_class)
Expand Down

0 comments on commit 17325de

Please sign in to comment.