Test JSON response of a POST Rails -



Test JSON response of a POST Rails -

i developing exercise in rails. have create users , allow them login. when user created, need send json respond (i know how that), don't know how test using rspec that response correct. attempt:

describe "with right input" before { @user.save } specify { expect(user.count).to eq(1) } "should respond json" post '/signup.json', :user => {:name => 'ppppp', :login => '1234567890'} json = json.parse(response.body) expect(json["user_name"]).to eq('ppppp') expect(json["login_count"]).to eq('1234567890') end end

when seek obtain error: nomethoderror:undefined method `post'

thank you!!

is controller spec? if yes, spec file placed under spec/controllers folder.

by default rspec assumes controller specs under folder. if file isn't in controllers folder add together :type => :controller illustration group.

refer rspec documentation.

hope helps.

ruby-on-rails json post rspec

Comments

Popular posts from this blog

maven fortify plugin : Unable to load build session with ID XXXXX .. See log file for more details -

c# - Primavera WebServices does not return any data -

android - Display emoji panel with genymotion - keyboard/touch input? -