Skip to content

Instantly share code, notes, and snippets.

@justinfrench
Created February 16, 2009 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinfrench/65108 to your computer and use it in GitHub Desktop.
Save justinfrench/65108 to your computer and use it in GitHub Desktop.
# 1. add this to formtastic_spec.rb inside the ":as => :select" describe block
it 'should have one option with a "selected" attribute' do
output_buffer.should have_tag('form li select option[@selected]', :count => 2) # the 2 is intentional
end
# 2. run the specs
expected
<form class="formtastic post" action="/posts" method="post" id="new_post"><li class="select optional" id="post_author_id_input"><label for="post_author_id">Author</label><select name="post[author_id]" id="post_author_id"><option value="37">Fred Smith</option>
<option selected="selected" value="42">Bob Rock</option></select>
</li></form>
to have 2 elements matching "form li select option[@selected]", but found 1
# 3. change the spec to only look for one
it 'should have one option with a "selected" attribute' do
output_buffer.should have_tag('form li select option[@selected]', :count => 1)
end
# 4. run the specs, they pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment