Skip to content

Commit

Permalink
Support do/end blocks with natural assertions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimweirich committed Dec 29, 2012
1 parent 13b19b7 commit 61be857
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rspec/given/natural_assertion.rb
Expand Up @@ -114,7 +114,8 @@ def extract_brace_block(sexp)
unless sexp.first == :program &&
sexp[1].first == :stmts_add &&
sexp[1][2].first == :method_add_block &&
sexp[1][2][2].first == :brace_block
(sexp[1][2][2].first == :brace_block || sexp[1][2][2].first == :do_block)
puts "DBG: sexp=#{sexp.inspect}"
source = Sorcerer.source(sexp)
fail RSpec::Given::InvalidThenError, "Unexpected code at #{source_line}\n#{source}"
end
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/rspec/given/natural_assertion_spec.rb
Expand Up @@ -107,6 +107,16 @@
Then { msg.should =~ /\b1 +<- +a\b/ }
end

context "with equals assertion with do/end" do
Given(:block) {
lambda do a == 2 end
}
Then { msg.should =~ /\bexpected: +1\b/ }
Then { msg.should =~ /\bto equal: +2\b/ }
Then { msg.should =~ /\bfalse +<- +a == 2\b/ }
Then { msg.should =~ /\b1 +<- +a\b/ }
end

context "with not-equals assertion" do
Given(:block) {
lambda { a != 1 }
Expand Down

0 comments on commit 61be857

Please sign in to comment.