Permalink
Browse files

! fixes rspec matchers

All of the matching is now done in a single RSpec::Matchers::Matcher instance. The thing that relies those executions together is a block execution, so local variables are fine.
  • Loading branch information...
1 parent f6ba7ed commit 94884f623315de0f0c96e105b523f9bedf9dcd6d @kschiess committed Jan 11, 2012
Showing with 18 additions and 17 deletions.
  1. +18 −17 lib/parslet/rig/rspec.rb
View
@@ -1,50 +1,51 @@
RSpec::Matchers.define(:parse) do |input, opts|
+ as = block = nil
+ result = trace = nil
match do |parser|
begin
- @result = parser.parse(input)
- @block ?
- @block.call(@result) :
- (@as == @result || @as.nil?)
+ result = parser.parse(input)
+ block ?
+ block.call(result) :
+ (as == result || as.nil?)
rescue Parslet::ParseFailed
- @trace = parser.error_tree.ascii_tree if opts && opts[:trace]
+ trace = parser.error_tree.ascii_tree if opts && opts[:trace]
false
end
end
failure_message_for_should do |is|
- if @block
+ if block
"expected output of parsing #{input.inspect}" <<
" with #{is.inspect} to meet block conditions, but it didn't"
else
"expected " <<
- (@as ?
+ (as ?
"output of parsing #{input.inspect}"<<
- " with #{is.inspect} to equal #{@as.inspect}, but was #{@result.inspect}" :
+ " with #{is.inspect} to equal #{as.inspect}, but was #{result.inspect}" :
"#{is.inspect} to be able to parse #{input.inspect}") <<
- (@trace ?
- "\n"+@trace :
+ (trace ?
+ "\n"+trace :
'')
end
end
failure_message_for_should_not do |is|
- if @block
+ if block
"expected output of parsing #{input.inspect} with #{is.inspect} not to meet block conditions, but it did"
else
"expected " <<
- (@as ?
+ (as ?
"output of parsing #{input.inspect}"<<
- " with #{is.inspect} not to equal #{@as.inspect}" :
+ " with #{is.inspect} not to equal #{as.inspect}" :
"#{is.inspect} to not parse #{input.inspect}, but it did")
end
end
# NOTE: This has a nodoc tag since the rdoc parser puts this into
# Object, a thing I would never allow.
- def as(expected_output = nil, &block) # :nodoc:
- @as = expected_output
- @block = block
- self
+ chain :as do |expected_output, &block|
+ as = expected_output
+ block = block
end
end

0 comments on commit 94884f6

Please sign in to comment.