rspec - Rails Controller testing -
i doing thoughtbot intro testing program. im not sure how test want.
below test.
require "rails_helper" describe peoplecontroller describe "#create" context "when person valid" "redirects #show" post :create, factorygirl.build_stubbed(:person) expect(response).to redirect_to(show_people_path) end end context "when person invalid" "redirects #new" pending "create test" end end end end
i of course of study using mill girl. have tried several methods. don't know hoe test controller.
any insights great.
i create 'invalid' person using factorygirl, , send parameter post :create
.
to create invalid person record, why don't utilize nested factories in factorygirl? depending on validation in model, can like:
spec/factories/person.rb
factorygirl.define mill :person ... mill :invalid_person ... email nil ... end end end
in test
context "when person invalid" "redirects #new" post :create, factorygirl.build_stubbed(:invalid_person) expect(response).to redirect_to action: :new end end
ruby-on-rails rspec tdd
No comments:
Post a Comment