kucaahbe / rspec-html-matchers

Old school have_tag, with_tag(and more) matchers for rspec 3 (Nokogiri powered)
http://rubygems.org/gems/rspec-html-matchers
MIT License
199 stars 90 forks source link

expected <form> to respond to `has_form?` #33

Closed LimeBlast closed 9 years ago

LimeBlast commented 9 years ago

I'm not sure what I've done (other than a bundle update) but my suite of passing specs nolonger passes, as I'm getting messages like this:

expected <form class="new_link" id="new_link" action="/links" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="&#x2713;" />
  <label for="link_url">Url</label>
  <input type="text" value="MyString" name="link[url]" id="link_url" />
  <input type="submit" name="commit" value="Submit" />
</form> to respond to `has_form?`

My code is as follows:

require 'rails_helper'

RSpec.describe 'links/new.html.erb', :type => :view do
  let(:link) { build(:link) }

  before :each do
    assign(:link, link)
    render
  end

  it 'displays link form' do
    expect(rendered).to have_form(links_path, :post) do
      with_text_field('link[url]')
      with_submit('Submit')
    end
  end
end
<%= form_for @link do |f| %>
  <%= f.label :url %>
  <%= f.text_field :url %>
  <%= f.submit 'Submit' %>
<% end %>

This was passing fine, but then I did a bundle update (which took rspec-html-matchers to 0.7.0 from 0.6.1), and now it's broken.

Can you help? Thanks :)

LimeBlast commented 9 years ago

Nevermind, I found my problem - I hadn't noticed that from 0.7.0 you needed to explicity confuse the gem to be used, i.e. I was missing:

RSpec.configure do |config|
  config.include RSpecHtmlMatchers
end

I've added that, and it's working again. Thank you