I'm writing a spec upon a file inside lib/ directory. And one of my methods in there returns a HTML string, but then I try something like:
expect(subject).to have_selector("p:eq(1)") do |first_p|
And it gives me the following error:
Failure/Error: expect(subject).to have_selector("p:eq(1)") do |first_p|
NoMethodError:
undefined method `has_selector?' for #<String:0x007f93798a8338>
How can I work around this? Should I wrap the string object with some another specific object? I've tried with Nokogiri::HTML.fragment() but it didn't work out neither. I suppose I should wrap it with some webrat's object or something like that, but I don't know how to get there. Thanks in advance.
I didn't feel very satisfied about using the type: :view
solution that I discovered earlier in this thread, despite it's a very valid one. The thing is that my spec for a file inside lib/
directory shouldn't be actually considered as a view spec.
So I did some further research over the internet and found out one that seems a better approach to me.
So considering the original example in this thread. You should just add the following line inside your describe block:
include Webrat::Matchers
So the final example would look like:
describe MyApp::UI::MyDecoratorClass do
include Webrat::Matchers
# ...
end