Re: [pickle] Advice on Pickle Refs

3 views
Skip to first unread message

Ian White

unread,
Jun 25, 2010, 6:14:35 AM6/25/10
to pickle-...@googlegroups.com
Hi there,

The model('user "fred"') method is what you want
The bang version raises an error if the model can't be found

If you are going to parse the multiline string, then something like the following should work.

refs = # code to parse string into picklerefs
# => ['user "ed"', 'user "jane"']
models = refs.map{|ref| model!(ref)}

once you have the models, you can populate your original string with the ids or whatever.

Let me know how you get on with this, if you come up with something general, i'd like to put something like this in pickle. A helper for replacing pickle refs and attributes in multiline strings could be very useful I think.

Cheers,
Ian

On 24 Jun 2010, at 21:16, Kris wrote:

> Hi, I was hoping to get some advice on using model refs outside of
> tables with Pickle. I am trying to test the output of a simple JSON
> API, and am trying to write a preprocessor that transforms my expected
> output with values obtained from pickle refs. Here's a simple
> example:
>
> - setup some model refs with pickle:
>
> Given the following users exist:
> | user | name |
> | ed | Edward |
> | jane | Jane |
> ...
>
> - verify the response against a sample JSON body requiring pre-
> processing:
>
> Then I should see the json:
> """
> [{ id: [user 'ed'].id, name: "Edward" },{ id: [user 'jane'].id,
> name: "Jane" }]
> """
>
> Assuming I have a simple convention for specifying and parsing the
> refs in my JSON message, I can't figure out how to actually get them
> from Pickle. I'm looking through the way tables are transformed right
> now but it's not yet clear on how it works just yet. Has anyone done
> something similar and know of a good approach in this case?
>
> Thanks,
>
> Kris
>
> --
> 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.
>

Reply all
Reply to author
Forward
0 new messages