A small rspec extension to verify simple form elements with the help of capybara.
Add this line to your application's Gemfile:
gem 'rspec-capybara-simple_form-rails'
And then execute:
$ bundle
Add the following lines to your spec_helper.rb
# load capybara
require 'capybara/rspec'
require 'rspec/capybara/simple_form'
In a view spec just use the following matchers
have_input_field(model, attribute, options)
have_textarea_field(model, attribute, options)
The following example illustrates a full example:
it "renders the form correct" do
# assign model
@app = assign(:app, build(:app))
# render the view
render
# do the checks
rendered.should have_input_field(@app, :name, :required => true)
rendered.should have_textarea_field(@app, :description, :required => true)
end
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request