Question

foo.should_receive( :save ).with( html )

Where html is an HTML string, but I don't want to check against specific HTML because that would make the test brittle.

Is there a way to check the length of the param that foo should receive? Is it possible to use a matcher or something like html.should include '<html'?

Working in RSpec.

Était-ce utile?

La solution

As stated in the comment above you can use a regex for the argument matcher.

foo.should_receive(:save).with(/<html/)

If you want to do more complicated assertions you can provide a block:

foo.should_receive(:save).with do |arg|
  arg.should include '<html'
end

Autres conseils

I don't see why that would not work using the code you provided. Maybe use include? instead. You also could use a regex to determine if it was HTML. While for this specific example it might be a little much, you may be able to determine more specific things about the html then just if it has that tag.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top