Model Not Known Error

46 views
Skip to first unread message

nick hammond

unread,
Oct 6, 2010, 4:01:33 AM10/6/10
to pickle
I'm working on a scenario right now and I think I've just been looking
at it too long and could use a second eye. I'm getting "The model: 'a
journal entry' is not known in this scenario. Use #create_model to
create, or #find_model to find, and store a reference in this
scenario. (Pickle::Session::ModelNotKnownError)" on the last step.

I know this has worked in the past because it's supposed to do a
lookup for the model. My other factories are loading fine and I have a
factory defined for journal_entry too. Am I not able to say "Then a
model should exist" without creating it with pickle first?

Scenario: Create a journal entry
Given I am signed in as "jo...@example.com"
And I am on the journal entries page
When I fill in "New journal entry" with "A new journal entry"
And I press "Create entry"
Then a journal entry should exist with description: "A new journal
entry", user: the user

# Factory

Factory.define :journal_entry do |j|
j.description "A sample journal entry"
end

The confusing part is that I can see that the proper regex is there
for journal_entry too.

The model: 'a journal entry' is not known in this scenario. Use
#create_model to create, or #find_model to find, and store a reference
in this scenario. (Pickle::Session::ModelNotKnownError)
./features/step_definitions/pickle_steps.rb:20:in `/^((?:(?:)|(?:
(?:a|an|another|the|that) )?(?:(?:(?:(?:first|last|(?:\d+(?:st|nd|rd|
th))) )?(?:journal[_ ]entry|account|permission|user))|(?:
(?:journal[_ ]entry|account|permission|user)(?::? "(?:[^\"]|\.)*")))))
should exist(?: with ((?:(?:\w+: (?:(?:(?:)|(?:(?:a|an|another|the|
that) )?(?:(?:(?:(?:first|last|(?:\d+(?:st|nd|rd|th))) )?
(?:journal[_ ]entry|account|permission|user))|(?:(?:journal[_ ]entry|
account|permission|user)(?::? "(?:[^\"]|\.)*"))))|(?:"(?:[^\"]|\.)*"|
nil|true|false|[+-]?[0-9_]+(?:\.\d+)?))), )*(?:\w+: (?:(?:(?:)|(?:(?:a|
an|another|the|that) )?(?:(?:(?:(?:first|last|(?:\d+(?:st|nd|rd|
th))) )?(?:journal[_ ]entry|account|permission|user))|(?:
(?:journal[_ ]entry|account|permission|user)(?::? "(?:[^\"]|\.)*"))))|
(?:"(?:[^\"]|\.)*"|nil|true|false|[+-]?[0-9_]+(?:\.\d+)?)))))?$/'

Rails 3
Pickle 0.4.2
Cucumber Rails 0.3.2
Factory girl rails 1.0

Any help is much appreciated.

David Lawton

unread,
Oct 6, 2010, 5:59:59 AM10/6/10
to pickle-...@googlegroups.com
Hey,

Should "Then a journal entry should exis..." not be "Then a Journal entry should exis..."?

I was always under the impression that it needed the actual Class name?

Could be wrong, usually am

David


--
You received this message because you are subscribed to the Google Groups "pickle" group.
To post to this group, send email to pickle-...@googlegroups.com.
To unsubscribe from this group, send email to pickle-cucumb...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pickle-cucumber?hl=en.




--
"I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage

nick hammond

unread,
Oct 6, 2010, 2:57:23 PM10/6/10
to pickle
I was getting this error because the model didn't exist which is
confusing because that's not the way Pickle used to be have, not sure
when it changed.

If you look at the steps within pickle for "Then a model exists" it's
using the find_model! method. If you look at this method in the gem it
is throwing the "ModelNotKnownError" when it can't find the record
which is why I was seeing this.

def find_model(a_model_name, fields = nil)
factory, name = *parse_model(a_model_name)

raise ArgumentError, "Can't find a model with an ordinal (e.g.
1st user)" if name.is_a?(Integer)

model_class = pickle_config.factories[factory].klass
fields = fields.is_a?(Hash) ? parse_hash(fields) :
parse_fields(fields)
conditions = convert_models_to_attributes(model_class, fields)
record = Pickle::Adapter.find_first_model(model_class,
conditions)

store_model(factory, name, record) if record

record
end

def find_model!(name, fields = nil)
find_model(name, fields) or raise ModelNotKnownError, name
end

Once the model is created within your application then the test will
pass. I believe the error it raised in the past was something along
the lines of "Record Not Found" instead of "Model not Known".

On Oct 6, 2:59 am, David Lawton <da...@davetheninja.net> wrote:
> Hey,
>
> Should "Then a journal entry should exis..." not be "Then a Journal entry
> should exis..."?
>
> I was always under the impression that it needed the actual Class name?
>
> Could be wrong, usually am
>
> David
>
> On 6 October 2010 16:01, nick hammond <n.r.hamm...@gmail.com> wrote:
>
>
>
>
>
> > I'm working on a scenario right now and I think I've just been looking
> > at it too long and could use a second eye. I'm getting "The model: 'a
> > journal entry' is not known in this scenario.  Use #create_model to
> > create, or #find_model to find, and store a reference in this
> > scenario. (Pickle::Session::ModelNotKnownError)" on the last step.
>
> > I know this has worked in the past because it's supposed to do a
> > lookup for the model. My other factories are loading fine and I have a
> > factory defined for journal_entry too. Am I not able to say "Then a
> > model should exist" without creating it with pickle first?
>
> >  Scenario: Create a journal entry
> >    Given I am signed in as "j...@example.com"
> > pickle-cucumb...@googlegroups.com<pickle-cucumber%2Bunsubscribe@ googlegroups.com>
> > .

Ian White

unread,
Oct 6, 2010, 2:59:54 PM10/6/10
to pickle-...@googlegroups.com
Hi Nick,

Thanks for the bug report, you;re right, the error message is confusing. I'll fix this soon.

Cheers,
Ian

> To unsubscribe from this group, send email to pickle-cucumb...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages