[rspec-users] specing controller post

ssmithstone stephen.smithstone at gmail.com
Tue Feb 2 05:00:30 EST 2010

A bit stuck here being new to ruby and rspec

Im trying to spec out a rails controller and using machinist to
generate a model

so in my spec i have

it "should create new client" do
    // creates me a hash of generated values using Foregey
    client = Client.plan
    // specify that I should be creating a new client with the hash
values from client
    //post to the server using my client hash
    post 'create' , :client => client

in my controller

def create
    client = Client.new(params[:client])

now this is failing with

Spec::Mocks::MockExpectationError: <Client(id: integer, created_at:
datetime, updated_at: datetime, title: string, lastname: string,
firstname: string, email: string) (class)> received :new with
unexpected arguments
({:title=>"Mr", :firstname=>"Ernest", :lastname=>"Burke", :email=>"rgarrett at blogtag.info"})
       got: ({"title"=>"Mr", "lastname"=>"Burke",
"firstname"=>"Ernest", "email"=>"rgarrett at blogtag.info"})

so why are my hash keys being transformed in string keys instead of
keeping them as symbols, or am I doing this wrong ?


More information about the rspec-users mailing list