How are you disabling the link? Is it a class you're adding? An attribute?
# Check for a link that has a "disabled" class:
page.should have_css("a.my_link.disabled")
page.should have_xpath("//a[@class='disabled']")
# Check for a link that has a "disabled" attribute:
page.should have_css("a.my_link[disabled]")
page.should have_xpath("//a[@class='disabled' and @disabled='disabled']")
# Check that the element is visible
find("a.my_link").should be_visible
find(:xpath, "//a[@class='disabled']").should be_visible
The actual xpath selectors may be incorrect. I don't use xpath often!
Another simple solution is to access the HTML attribute you are looking for with []:
find('#my_element')['class']
# => "highlighted clearfix some_other_css_class"
find('a#my_element')['href']
# => "http://example.com
# or in general, find any attribute, even if it does not exist
find('a#my_element')['no_such_attribute']
# => ""
Note that Capybara will automatically try to wait for asynchronous requests to finish, but it may not work in some cases:
page.should have_link('It will work this way!', {:href => '/clowns?ordered_by=clumsyness', :class => "smile"})
have_link expects a hash of options which is empty if you do not provide any. You can specify any attributes the link should have - just make sure you pass all the options in ONE hash.
Hope this helps
PS: For attributes like data-method you have to pass the attribute name as a string since the hyphen breaks the symbol.
Another simple solution is to access the HTML attribute you are looking for with []
Here is an example:
let(:action_items) { page.find('div.action_items') }
it "action items displayed as buttons" do
action_items.all(:css, 'a').each do |ai|
expect(ai[:class]).to match(/btn/)
end
end
I recommend using have_link and find_link(name)[:disabled] in two separate assertions. While performing the second assertion alone is simpler, this makes error messages about missing links look nicer, making your test results easier to read.
expect(page).to have_link "Example"
expect(find_link("Example")[:disabled]).to be false
Note that "Example" can be changed to the name or id of the link.