Rspec partial rendering madness

18 views
Skip to first unread message

bas...@braincheck.com

unread,
Oct 12, 2016, 2:43:19 PM10/12/16
to SimpleForm
Hey all,
    Hope everyone is doing fantasmic.  I am trying to rspec a partial with simple form but with no joy :(.  Can anyone tell me why this could be failing:

======= app/views/users/_form.html.haml ===========
= simple_form_for user do |f|
= f.input :first_name
= f.input :last_name
= f.submit
====== spec/views/users/_form.html.haml_spec.rb ====
require 'rails_helper'

describe 'users/_form.html.haml', type: :view do
context 'user form' do
it 'shows user data' do
user = User.new(first_name: 'Joe', last_name: 'Smith')
render partial: 'users/form', locals: { user: user }
expect(rendered).to have_content 'Joe'
end
end
end
==========================================
Result is:
Failures:

  1) users/_form.html.haml user form shows user data
     Failure/Error: expect(rendered).to have_content 'Joe'
       expected to find text "Joe" in "* First name * Last name"
     # ./spec/views/users/_form.html.haml_spec.rb:8:in `block (3 levels) in <top (required)>'
     # ./spec/support/rspec_helpers/database_cleaner.rb:11:in `block (3 levels) in <top (required)>'
     # ./spec/support/rspec_helpers/database_cleaner.rb:10:in `block (2 levels) in <top (required)>'
==========================================

I have been scratching my head for a while, but can't figure it out.  The form actually works when you render it in a browser.  Just not when rendered as a partial.

Any help is greatly appreciated.

regards,

B


Darryl Wolfaardt

unread,
Oct 12, 2016, 3:03:23 PM10/12/16
to plataformate...@googlegroups.com

I think the spec is looking for the partial relative to the spec directory/folder

This line in the error seems to indicate that.  # ./spec/views/users/_form.html.haml_spec.rb:8:in `block (3 levels) in <top (required)>'

When the partial is used in the view it assumes the folder structure of the model. So I would say you can't use it the same way in the test.

D


--
You received this message because you are subscribed to the Google Groups "SimpleForm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plataformatec-simpleform+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bas...@braincheck.com

unread,
Oct 12, 2016, 3:23:14 PM10/12/16
to SimpleForm, dar...@herebemagic.com
The form is being actually rendered.  Just the input fields are not being populated.  If I put a "puts rendered" in the test the following is being printed:
<form novalidate="novalidate" class="simple_form new_user" id="new_user" action="/users" accept-charset="UTF-8" method="post"><input name="utf8" type="hidden" value="&#x2713;" /><div class="form-group string required user_first_name"><label class="control-label string required" for="user_first_name"><abbr title="required">*</abbr> First name</label><input class="form-control string required" type="text" value="Joe" name="user[first_name]" id="user_first_name" /></div>
<div class="form-group string required user_last_name"><label class="control-label string required" for="user_last_name"><abbr title="required">*</abbr> Last name</label><input class="form-control string required" type="text" value="Smith" name="user[last_name]" id="user_last_name" /></div>
<input type="submit" name="commit" value="Create User" />
Reply all
Reply to author
Forward
0 new messages