[rspec-users] how to write nested XPath matchers

David Chelimsky dchelimsky at gmail.com
Tue Feb 17 07:23:12 EST 2009


On Mon, Feb 16, 2009 at 8:21 PM, Phlip <phlip2005 at gmail.com> wrote:
> David Chelimsky wrote:
>
>> When RSpec is used as customer facing, they see the docstrings
>> (strings passed to describe() and it()), not the internal code. That's
>> for developers.
>
> Then why the .should stuff? I'm a developer - technically - and I never
> needed it!

http://dannorth.net/introducing-bdd

>
> But enough sophistry: Back to business...
>
>> Take a look at
>> http://github.com/dchelimsky/rspec/blob/f6c75b1417d9178d4dcaaf9e892e23474d340ff6/lib/spec/matchers/wrap_expectation.rb,
>> I think it'll solve this problem.
>
> This gives the same issue:
>
>  class BeXmlWith
>
>    def matches?(stwing, &block)
>      waz_xdoc = @xdoc
>
>      @scope.wrap_expectation self do
>        @scope.assert_xhtml stwing
>        return (block || @block || proc{}).call
>      end
>    ensure
>      @xdoc = waz_xdoc
>    end
>
>    attr_accessor :failure_message
>
> The same error message for a stray nil:
>
>
> 1)
> '/users/new should have xpathic tags' FAILED
> You have a nil object when you didn't expect it!
> You might have expected an instance of Array.
> The error occurred while evaluating nil.first
> ./spec/views/users/new.html.erb_spec.rb:50:
>
> line 50 is just this one:
>
>    response.body.should be_xml_with do

That's the line you want to look at to know which example is failing.
To see the full backtrace, use the --backtrace (-b) option.

To learn about the various rspec options, use the --help (-h) option.

>
> and yes the response.body is populated...



>
> --
>  Phlip
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list