{"action":"created","issue":{"url":"https://api.github.com/repos/everydayrails/rails-4-1-rspec-3-0/issues/67","labels_url":"https://api.github.com/repos/everydayrails/rails-4-1-rspec-3-0/issues/67/labels{/name}","comments_url":"https://api.github.com/repos/everydayrails/rails-4-1-rspec-3-0/issues/67/comments","events_url":"https://api.github.com/repos/everydayrails/rails-4-1-rspec-3-0/issues/67/events","html_url":"https://github.com/everydayrails/rails-4-1-rspec-3-0/issues/67","id":104414529,"number":67,"title":"error with invalid contact for controller spec","user":{"login":"tinaoct1","id":13805490,"avatar_url":"https://avatars.githubusercontent.com/u/13805490?v=3","gravatar_id":"","url":"https://api.github.com/users/tinaoct1","html_url":"https://github.com/tinaoct1","followers_url":"https://api.github.com/users/tinaoct1/followers","following_url":"https://api.github.com/users/tinaoct1/following{/other_user}","gists_url":"https://api.github.com/users/tinaoct1/gists{/gist_id}","starred_url":"https://api.github.com/users/tinaoct1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tinaoct1/subscriptions","organizations_url":"https://api.github.com/users/tinaoct1/orgs","repos_url":"https://api.github.com/users/tinaoct1/repos","events_url":"https://api.github.com/users/tinaoct1/events{/privacy}","received_events_url":"https://api.github.com/users/tinaoct1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-02T06:56:13Z","updated_at":"2015-09-03T01:17:27Z","closed_at":null,"body":"This is my Controller spec:\r\n\r\ndescribe 'POST#create' do\r\n\t\tcontext \"with valid attributes\" do\r\n\t\t\tit \"saves the new contact in the database\" do\r\n\t\t\t\texpect {\r\n\t\t\t\t\tpost :create, contact: attributes_for(:contact)\r\n\t\t\t\t}.to change(Contact, :count).by(1)\r\n\t\t\tend\r\n\r\n\t\t\tit \"redirects to contacts#show\" do\r\n\t\t\t\tpost :create, contact: attributes_for(:contact)\r\n\t\t\t\texpect(response).to redirect_to contact_path(assigns[:contacts])\r\n\t\t\tend\r\n\t\tend\r\n\r\n\t\tcontext \"with invalid attributes\" do\r\n\t\t\tit \"does not save the new contact in the database\" do\r\n          \t\texpect{\r\n\t\t\t \t\tpost :create,\r\n\t\t\t\t\tcontact: attributes_for(:invalid_contact)\r\n \t\t\t\t}.not_to change(Contact, :count)\r\n\t\t\tend\r\n\r\n\t\t\tit \"re-renders the new template\" do\r\n\t\t\t\tpost :create, contact: attributes_for(:invalid_contact)\r\n\t\t\t\texpect(response).to render_template :new\r\n\t\t\tend\r\n\t\tend\r\n\tend\r\n\r\nI am getting the following error when i am running the POST#create for an invalid contact:\r\n\r\n\r\n\r\nContactsController\r\n  GET#show\r\n    assigns the requested contact to @contact\r\n    renders the :show template\r\n  GET#new\r\n    assigns a new contact to @contact\r\n    renders the :new template\r\n  GET#edit\r\n    assigns the requested contact to @contact\r\n    renders the :edit template\r\n  GET#index\r\n    lists the entries in the phonebook\r\n    renders the :index template\r\n  POST#create\r\n    with valid attributes\r\n      saves the new contact in the database\r\n      redirects to contacts#show\r\n    with invalid attributes\r\n      does not save the new contact in the database (FAILED - 1)\r\n      re-renders the new template\r\n\r\nContact\r\n  has a valid factory\r\n  Contact\r\n    is invalid without a name\r\n    is invalid without a number\r\n    is invalid if the phone number is not an integer\r\n    is invalid with a duplicate phone number\r\n\r\nFailures:\r\n\r\n  1) ContactsController POST#create with invalid attributes does not save the new contact in the database\r\n     Failure/Error: contact: attributes_for(:invalid_contact)\r\n     NameError:\r\n       uninitialized constant InvalidContact\r\n     # ./spec/controllers/contacts_controller_spec.rb:84:in `block (5 levels) in <top (required)>'\r\n     # ./spec/controllers/contacts_controller_spec.rb:82:in `block (4 levels) in <top (required)>'\r\n\r\nFinished in 0.28958 seconds (files took 1.54 seconds to load)\r\n17 examples, 1 failure\r\n\r\nFailed examples:\r\n\r\nrspec ./spec/controllers/contacts_controller_spec.rb:81 # ContactsController POST#create with invalid attributes does not save the new contact in the database"},"comment":{"url":"https://api.github.com/repos/everydayrails/rails-4-1-rspec-3-0/issues/comments/137294526","html_url":"https://github.com/everydayrails/rails-4-1-rspec-3-0/issues/67#issuecomment-137294526","issue_url":"https://api.github.com/repos/everydayrails/rails-4-1-rspec-3-0/issues/67","id":137294526,"user":{"login":"ruralocity","id":53491,"avatar_url":"https://avatars.githubusercontent.com/u/53491?v=3","gravatar_id":"","url":"https://api.github.com/users/ruralocity","html_url":"https://github.com/ruralocity","followers_url":"https://api.github.com/users/ruralocity/followers","following_url":"https://api.github.com/users/ruralocity/following{/other_user}","gists_url":"https://api.github.com/users/ruralocity/gists{/gist_id}","starred_url":"https://api.github.com/users/ruralocity/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ruralocity/subscriptions","organizations_url":"https://api.github.com/users/ruralocity/orgs","repos_url":"https://api.github.com/users/ruralocity/repos","events_url":"https://api.github.com/users/ruralocity/events{/privacy}","received_events_url":"https://api.github.com/users/ruralocity/received_events","type":"User","site_admin":false},"created_at":"2015-09-03T01:17:27Z","updated_at":"2015-09-03T01:17:27Z","body":"Try this for your factory:\r\n\r\n```\r\nFactoryGirl.define do\r\n  factory :contact do\r\n    name { Faker::Name.name}\r\n    number { Faker::Number.number(10)}\r\n\r\n    factory :invalid_contact do\r\n      name nil\r\n      number nil\r\n    end\r\n  end\r\nend\r\n```\r\n\r\nSee how `:invalid_contact` is nested within the main `:contact`factory?"}}