Permalink
Browse files

Backwards-update raise_error and cover all specs

  • Loading branch information...
1 parent 3909598 commit 763f5df0e27adcf6ba6c9d66ee0538621656e0e2 @txus committed Nov 15, 2010
View
@@ -17,13 +17,14 @@ def be_a(kind)
end
alias_method :be_kind_of, :be_a
alias_method :be_a_kind_of, :be_a
+ alias_method :be_an, :be_a
def include(member)
Inclusion.new(member)
end
- def raise_error(exception_class, message)
- RaiseError.new(exception_class, message)
+ def raise_error(*args)
+ RaiseError.new(*args)
end
def method_missing(m,*args)
@@ -2,7 +2,7 @@ module Stendhal
module Matchers
class RaiseError < AbstractMatcher
- def initialize(exception_class, message = nil)
+ def initialize(exception_class = Exception, message = nil)
if exception_class.new.is_a?(Exception)
@target = exception_class.new(message.to_s)
@message_given = !!message
@@ -17,13 +17,27 @@ module Stendhal
end
end
- describe "#be_a" do
+ describe "#be_a / #be_an" do
it 'creates a new kind expectation' do
Matchers::Kind.should_receive(:new).with(Fixnum)
object.be_a(Fixnum)
end
end
+ describe "#include" do
+ it 'creates a new inclusion expectation' do
+ Matchers::Inclusion.should_receive(:new).with(3)
+ object.include(3)
+ end
+ end
+
+ describe "#raise_error" do
+ it 'creates a new raise_error expectation' do
+ Matchers::RaiseError.should_receive(:new).with(StandardError)
+ object.raise_error(StandardError)
+ end
+ end
+
describe "#be_whatever" do
it 'creates a new predicate expectation' do
Matchers::Predicate.should_receive(:new).with(:frozen?)
@@ -155,7 +155,7 @@ module Mocks
end
describe "#verify" do
- it 'registers a call for the given expectation' do
+ it 'verifies if times_called equals times_expected' do
subject.stub(:times_called).and_return 2
subject.stub(:times_expected).and_return 1
@@ -13,13 +13,13 @@ module Stendhal
group.description.must eq("docstring")
end
- pending "allows example declaration inside the block" do
- expect {
+ it "allows example declaration inside the block" do
+ lambda {
ExampleGroup.new("docstring") do
it "does something" do
end
end
- }.to_not raise_error
+ }.must_not raise_error
end
describe "#add_example" do
@@ -77,6 +77,9 @@ module Stendhal
@pending_example.does_not_expect(:run)
@group.run
+
+ ExampleGroup.destroy_all
+ Example.destroy_all
end
it "runs all its children" do
@@ -101,6 +104,9 @@ module Stendhal
g.expects(:run)
end
@group.run
+
+ ExampleGroup.destroy_all
+ Example.destroy_all
end
it "returns an array with total examples, failures and pendings" do
@@ -122,6 +128,9 @@ module Stendhal
@group.add_example_group("another group")
@group.run.must eq([6,1,1])
+
+ ExampleGroup.destroy_all
+ Example.destroy_all
end
end
@@ -130,6 +139,9 @@ module Stendhal
example_group = ExampleGroup.new("group")
example_group.add_example_group(ExampleGroup.new("other group"))
example_group.example_groups.first.has_parent?.must eq(true)
+
+ ExampleGroup.destroy_all
+ Example.destroy_all
end
end
@@ -141,6 +153,9 @@ module Stendhal
ExampleGroup.new("group")
ExampleGroup.count.must eq(1)
+
+ ExampleGroup.destroy_all
+ Example.destroy_all
end
end
describe "#run_all" do
@@ -154,6 +169,9 @@ module Stendhal
group2.stubs(:run) { [1,0,1] }
ExampleGroup.run_all.must eq([2,2,4])
+
+ ExampleGroup.destroy_all
+ Example.destroy_all
end
end
end
@@ -24,32 +24,32 @@ module Stendhal
example.run
end
- pending "captures unmet expectations" do
+ it "captures unmet expectations" do
example = Example.new("docstring") do
raise Stendhal::Exceptions::ExpectationNotMet.new("expected this example to be awesome")
end
- # expect {example.run}.to_not raise_error
+ lambda {example.run}.must_not raise_error
example.run
- example.should be_failed
- example.failed_message.should eq("expected this example to be awesome")
+ example.must be_failed
+ example.failed_message.must eq("expected this example to be awesome")
end
- pending "captures exceptions" do
+ it "captures exceptions" do
example = Example.new("docstring") do
raise "error"
end
- # expect {example.run}.to_not raise_error
+ lambda {example.run}.must_not raise_error
example.run
- example.should be_aborted
+ example.must be_aborted
end
- pending "captures everything else" do
+ it "captures everything else" do
example = Example.new("docstring") do
hello my dear reader
end
- # expect {example.run}.to_not raise_error
+ lambda {example.run}.must_not raise_error
example.run
- example.should be_aborted
+ example.must be_aborted
end
it "verifies all message expectations after running the block" do
@@ -7,11 +7,6 @@ module Matchers
matcher.target.must eq("target")
end
- pending 'does not implement #match' do
- matcher = AbstractMatcher.new("target")
- # expect { matcher.match("whatever") }.to raise_error(NotImplementedError)
- end
-
end
end
end
@@ -8,12 +8,12 @@ module Matchers
matcher.match("string").must be_true
end
- pending 'fails when original and target objects are unequivalent' do
+ it 'fails when original and target objects are unequivalent' do
matcher = Equality.new("string")
expected_message = %q{expected "string", got "other string"}
- expect {
+ lambda {
matcher.match("other string")
- }.to raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
+ }.must raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
end
context "with :negative => true" do
@@ -23,12 +23,12 @@ module Matchers
matcher.match("other string", :negative => true).must be_true
end
- pending 'fails otherwise' do
+ it 'fails otherwise' do
matcher = Equality.new("string")
expected_message = %q{expected something different than "string", got "string"}
- expect {
+ lambda {
matcher.match("string", :negative => true)
- }.to raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
+ }.must raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
end
end
@@ -8,20 +8,20 @@ module Matchers
matcher.match([2, "string"]).must be_true
end
- pending 'fails when original does not respond to :include?' do
+ it 'fails when original does not respond to :include?' do
matcher = Inclusion.new(2)
expected_message = %q{expected 3 to include 2, but the former cannot include any object}
- expect {
+ lambda {
matcher.match(3)
- }.to raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
+ }.must raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
end
- pending 'fails when original does not include the target' do
+ it 'fails when original does not include the target' do
matcher = Inclusion.new(2)
expected_message = %q{expected ["string"] to include 2}
- expect {
+ lambda {
matcher.match(["string"])
- }.to raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
+ }.must raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
end
context "with :negative => true" do
@@ -31,20 +31,20 @@ module Matchers
matcher.match(["other string"], :negative => true).must be_true
end
- pending 'fails when original does not respond to :include?' do
+ it 'fails when original does not respond to :include?' do
matcher = Inclusion.new("string")
expected_message = %q{expected 3 not to include "string", but the former cannot include any object}
- expect {
+ lambda {
matcher.match(3, :negative => true)
- }.to raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
+ }.must raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
end
- pending 'fails when original includes the target' do
+ it 'fails when original includes the target' do
matcher = Inclusion.new("string")
expected_message = %q{expected ["string"] not to include "string"}
- expect {
+ lambda {
matcher.match(["string"], :negative => true)
- }.to raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
+ }.must raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
end
end
@@ -8,12 +8,12 @@ module Matchers
matcher.match(3).must be_true
end
- pending 'fails otherwise' do
+ it 'fails otherwise' do
matcher = Kind.new(Fixnum)
expected_message = %q{expected 3.2 to be a Fixnum}
- expect {
+ lambda {
matcher.match(3.2)
- }.to raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
+ }.must raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
end
context "with :negative => true" do
@@ -23,12 +23,12 @@ module Matchers
matcher.match("string", :negative => true).must be_true
end
- pending 'fails otherwise' do
+ it 'fails otherwise' do
matcher = Kind.new(Numeric)
expected_message = %q{expected 3 not to be a Numeric}
- expect {
+ lambda {
matcher.match(3, :negative => true)
- }.to raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
+ }.must raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
end
end
@@ -8,12 +8,12 @@ module Matchers
matcher.match("string".freeze).must be_true
end
- pending 'fails when it returns false' do
+ it 'fails when it returns false' do
matcher = Predicate.new(:frozen?)
expected_message = %q{expected "string" to be frozen}
- expect {
+ lambda {
matcher.match("string")
- }.to raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
+ }.must raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
end
context "with :negative => true" do
@@ -23,12 +23,12 @@ module Matchers
matcher.match("string", :negative => true).must be_true
end
- pending 'fails otherwise' do
+ it 'fails otherwise' do
matcher = Predicate.new(:frozen?)
expected_message = %q{expected "string" not to be frozen}
- expect {
+ lambda {
matcher.match("string".freeze, :negative => true)
- }.to raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
+ }.must raise_error(Stendhal::Exceptions::ExpectationNotMet, expected_message)
end
end
Oops, something went wrong.

0 comments on commit 763f5df

Please sign in to comment.