Skip to content

Commit

Permalink
Better error message when you specify an invalid method
Browse files Browse the repository at this point in the history
Signed-off-by: Justin French <justin@indent.com.au>
  • Loading branch information
xaviershay authored and justinfrench committed Jan 12, 2009
1 parent e5d03b3 commit a8f1644
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/justin_french/formtastic.rb
Expand Up @@ -116,7 +116,8 @@ class SemanticFormBuilder < ActionView::Helpers::FormBuilder
# <% end %>
# <% end %>
def input(method, options = {})
raise NoMethodError unless @object.respond_to?(method)
raise NoMethodError.new("NoMethodError: form object does not respond to \"#{method}\"") unless @object.respond_to?(method)


options[:required] = method_required?(method, options[:required])
options[:label] ||= method.to_s.titleize
Expand Down
4 changes: 2 additions & 2 deletions spec/formtastic_spec.rb
Expand Up @@ -221,9 +221,9 @@ class Author; end
}.should raise_error(ArgumentError)
end

it 'should raise an error when the object does not respond to the method supplied in the first argument' do
it 'should raise a helpful error when the object does not respond to the method supplied in the first argument' do
semantic_form_for(@new_post) do |builder|
lambda { builder.input(:method_on_post_that_doesnt_exist) }.should raise_error(NoMethodError)
lambda { builder.input(:method_on_post_that_doesnt_exist) }.should raise_error(NoMethodError, /method_on_post_that_doesnt_exist/)
end
end

Expand Down

0 comments on commit a8f1644

Please sign in to comment.