Permalink
Browse files

0.4.7 - Better error message for not finding a model (as opposed to n…

…ot referring to a model)
  • Loading branch information...
1 parent 868eab5 commit 05fd3b2a8c44f2114b204e0873ce20f78143166f @ianwhite committed Mar 24, 2011
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- pickle (0.4.6)
+ pickle (0.4.7)
cucumber (>= 0.8)
rake
View
@@ -1,3 +1,10 @@
+== 0.4.7
+
+* 2 minor improvements
+ * Better error message for failing to find a model [Ian White, reported by Yuval Karmi]
+ * dev deps updated to latest cucumber & cucumber-rails [Ian White]
+
+
== 0.4.6
Documentation updates
@@ -59,5 +59,8 @@ Feature: I can easily create models from my factories
And the fancy fork: "of cornwood" should be fancy
Scenario: create a tine with a missing fork
- Then the following should raise Pickle::Session::ModelNotKnownError: "Given a tine exists with fork: the fork"
+ Then the following should raise a Pickle::Session::ModelNotKnownError:
+ """
+ Given a tine exists with fork: the fork
+ """
@@ -36,4 +36,11 @@ Feature: I can easily create models from my blueprints
And 2 spoons should exist with round: true
And the first spoon should be round
- And the last spoon should be round
+ And the last spoon should be round
+
+ Scenario: ModelNotKnownError should be informative when failing to find
+ Given a spoon exists with round: true
+ Then the following should raise a Pickle::Session::ModelNotFoundError with "Can't find a spoon with round: false from the orm in this scenario":
+ """
+ Then a spoon should exist with round: false
+ """
@@ -1,3 +1,7 @@
-Then /^the following should raise Pickle::Session::ModelNotKnownError: "([^"]*)"$/ do |step|
- lambda { steps step }.should raise_error(Pickle::Session::ModelNotKnownError)
+Then /^the following should raise an? ([\w:]+):$/ do |error, step|
+ lambda { steps step }.should raise_error(error.constantize)
+end
+
+Then /^the following should raise an? ([\w:]+) with "([^"]*)":$/ do |error, message, step|
+ lambda { steps step }.should raise_error(error.constantize, message)
end
View
@@ -5,14 +5,17 @@ class ModelNotKnownError < RuntimeError
def initialize(name, message = nil)
@name = name
- @message = message || "The model: '#{name}' is not known in this scenario. Use #create_model to create, or #find_model to find, and store a reference in this scenario."
+ @message = message.presence || "The model: '#{name}' is not known in this scenario. Use #create_model to create, or #find_model to find, and store a reference in this scenario."
end
def to_s
@message
end
end
+ class ModelNotFoundError < RuntimeError
+ end
+
class << self
def included(world_class)
proxy_to_pickle_parser(world_class)
@@ -67,7 +70,7 @@ def find_model(a_model_name, fields = nil)
end
def find_model!(name, fields = nil)
- find_model(name, fields) or raise ModelNotKnownError, name
+ find_model(name, fields) or raise ModelNotFoundError, "Can't find #{name}#{" with #{fields}" if fields.present?} from the orm in this scenario"
end
def find_models(factory, fields = nil)
View
@@ -1,3 +1,3 @@
module Pickle
- VERSION = "0.4.6"
+ VERSION = "0.4.7"
end
@@ -253,7 +253,7 @@ class Model
it "should call raise error if find_model returns nil" do
should_receive(:find_model).with('name', 'fields').and_return(nil)
- lambda { find_model!('name', 'fields') }.should raise_error(Pickle::Session::ModelNotKnownError)
+ lambda { find_model!('name', 'fields') }.should raise_error(Pickle::Session::ModelNotFoundError)
end
end

0 comments on commit 05fd3b2

Please sign in to comment.