cheers for the response , seem that attributes is missing from hash on my system <br><br>all i did was the blueprint with a standard hash<br><br>client = { :title => "Mr }<br><br>client.attributes<br><br>NoMethodError: undefined method `attributes' for {:title=>"Mr"}:Hash<br>
<br>is attributes added on by rails ?<br><br>if so my setup must be wrong<br><br><div class="gmail_quote">On 2 February 2010 12:07, J. B. Rainsberger <span dir="ltr"><<a href="mailto:jbrainsberger@gmail.com">jbrainsberger@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div class="im">On Tue, Feb 2, 2010 at 04:24, Stephen Smithstone <<a href="mailto:ssmithstone@me.com">ssmithstone@me.com</a>> wrote:<br>
<br>
> A bit stuck here being new to ruby and rspec<br>
<br>
</div>Welcome. I hope you like the experience. Good news: we've seen what<br>
you've done a thousand times and so it's quite easy to explain.<br>
<div><div></div><div class="h5"><br>
> it "should create new client" do<br>
> // creates me a hash of generated values using Foregey<br>
> client = Client.plan<br>
> // specify that I should be creating a new client with the hash values<br>
> from client<br>
> Client.should_receive(:new).with(client)<br>
> //post to the server<br>
> post 'create' , :client => client<br>
> end<br>
><br>
> in my controller<br>
><br>
> def create<br>
> client = Client.new(params[:client])<br>
> end<br>
><br>
> now this is failing with<br>
><br>
> Spec::Mocks::MockExpectationError: <Client(id: integer, created_at:<br>
> datetime, updated_at: datetime, title: string, lastname: string, firstname:<br>
> string, email: string) (class)> received :new with unexpected arguments<br>
> expected: ({:title=>"Mr", :firstname=>"Ernest", :lastname=>"Burke",<br>
> :email=>"<a href="mailto:rgarrett@blogtag.info">rgarrett@blogtag.info</a>"})<br>
> got: ({"title"=>"Mr", "lastname"=>"Burke", "firstname"=>"Ernest",<br>
> "email"=>"<a href="mailto:rgarrett@blogtag.info">rgarrett@blogtag.info</a>"})<br>
><br>
> is there a way to specify to use symbols instead of the strings as keys, as<br>
> I dont want to be doing<br>
><br>
> :client => { "title" => client.title , ............ }<br>
><br>
> as the client model may change over time<br>
<br>
</div></div>Try Client.should_receive(:new).with(client.attributes), because the<br>
#attributes method turns a model into a Hash of symbol to value. It<br>
uses string keys instead of symbol keys, but that shouldn't hurt you.<br>
<br>
Good luck.<br>
--<br>
J. B. (Joe) Rainsberger :: <a href="http://www.jbrains.ca" target="_blank">http://www.jbrains.ca</a> ::<br>
<a href="http://blog.thecodewhisperer.com" target="_blank">http://blog.thecodewhisperer.com</a><br>
Diaspar Software Services :: <a href="http://www.diasparsoftware.com" target="_blank">http://www.diasparsoftware.com</a><br>
Author, JUnit Recipes<br>
2005 Gordon Pask Award for contribution to Agile practice :: Agile<br>
2010: Learn. Practice. Explore.<br>
_______________________________________________<br>
rspec-users mailing list<br>
<a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/rspec-users" target="_blank">http://rubyforge.org/mailman/listinfo/rspec-users</a><br>
</blockquote></div><br>