rspec
is very helpful on any errored specs. Let's check it out.
Create a file called errors_spec.rb
:
describe "#errors" do
it "math should work" do
expect(4 + 4).to eq(4)
end
it "hashes should match" do
expect({"one"=> 1, "two"=> 2}).to eq({"one"=>1, "two"=>4})
end
it "should be in range" do
expect("superman").to start_with("cat").or end_with("woman")
end
end
Your output should now have some errors similar to:
...
2) #errors hashes should match
Failure/Error: expect({"one"=> 1, "two"=> 2}).to eq({"one"=>1, "two"=>4})
expected: {"one"=>1, "two"=>4}
got: {"one"=>1, "two"=>2}
(compared using ==)
Diff:
@@ -1,3 +1,3 @@
"one" => 1,
-"two" => 4,
+"two" => 2,
# ./errors_spec.rb:9:in `block (2 levels) in <top (required)>'
...
As you can see, rspec
provides pretty nice diffs on what when wrong.