difference in have_selector matcher

12 views
Skip to first unread message

Javix

unread,
Feb 26, 2013, 10:10:19 AM2/26/13
to rs...@googlegroups.com
I can't figure what is the difference betwen these 2 matchers definition:

page.should have_selection('title', text: full_title('Home')) - fails, can(t find the title content
page.should have_selection('title', full_title('Home')) - passes

I defined the 'full_title' in ApplicationHelper:

module ApplicationHelper
  def full_title(page_title)
    base_title = I18n.t(:base_title)
    if page_title.empty?
      base_title
    else
      "#{base_title} | #{page_title}"
    end
  end
end

and required in in features/env.rb to use in Cucumber:

World(ApplicationHelper)

In the aplication layout page the call to full_title is done as follows:

<title><%= full_title(yield(:title)) %></title>

And in the home/index page it is used like that:

<% provide(:title, 'Home') %>

Any ideas? Thank you.


David Chelimsky

unread,
Feb 26, 2013, 11:10:04 AM2/26/13
to rs...@googlegroups.com
On Tue, Feb 26, 2013 at 10:10 AM, Javix <s.ca...@gmail.com> wrote:
> I can't figure what is the difference betwen these 2 matchers definition:
>
> page.should have_selection('title', text: full_title('Home')) - fails, can't find the title content
> page.should have_selection('title', full_title('Home')) - passes

Not sure why the first one can't find the content, but if it can't it
is failing correctly. The second one is a false positive because the
result of full_title('Home') is never evaluated by has_selector? (see
http://rubydoc.info/gems/capybara/Capybara/Node/Matchers#has_selector%3F-instance_method)

If you want any more detailed help you might want to try the Cucumber
and Capybara user lists, since those are the tools you're really
interacting with - the only thing rspec does here is translate
`have_selector` to `has_selector?`.

HTH,
David

>
> I defined the 'full_title' in ApplicationHelper:
>
> module ApplicationHelper
> def full_title(page_title)
> base_title = I18n.t(:base_title)
> if page_title.empty?
> base_title
> else
> "#{base_title} | #{page_title}"
> end
> end
> end
>
> and required in in features/env.rb to use in Cucumber:
>
> World(ApplicationHelper)
>
> In the aplication layout page the call to full_title is done as follows:
>
> <title><%= full_title(yield(:title)) %></title>
>
> And in the home/index page it is used like that:
>
> <% provide(:title, 'Home') %>
>
> Any ideas? Thank you.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "rspec" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rspec+un...@googlegroups.com.
> To post to this group, send email to rs...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rspec/-/0YIfTdVPrm4J.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Javix

unread,
Feb 26, 2013, 2:23:26 PM2/26/13
to rs...@googlegroups.com


On Tuesday, February 26, 2013 5:10:04 PM UTC+1, dchel...@gmail.com wrote:
On Tue, Feb 26, 2013 at 10:10 AM, Javix <s.ca...@gmail.com> wrote:
> I can't figure what is the difference betwen these 2 matchers definition:
>
> page.should have_selection('title', text: full_title('Home')) - fails, can't find the title content
> page.should have_selection('title', full_title('Home')) - passes

Not sure why the first one can't find the content, but if it can't it
is failing correctly. The second one is a false positive because the
result of full_title('Home') is never evaluated by has_selector? (see
http://rubydoc.info/gems/capybara/Capybara/Node/Matchers#has_selector%3F-instance_method)

If you want any more detailed help you might want to try the Cucumber
and Capybara user lists, since those are the tools you're really
interacting with - the only thing rspec does here is translate
`have_selector` to `has_selector?`.

Thanks a lot, David, for your explanation. I'll post the same question at Cucumber and/or Capybara user lists.
Regards,

Serguei
Reply all
Reply to author
Forward
0 new messages