vendredi 25 septembre 2015

rails rspec capybara testing ActiveRecord::RecordInvalid:

Hello every one im getting a error that i don't know how to fix and im not sure why is it even popping up

require 'spec_helper'

feature "Profile page" do
    scenario "viewing" do
        user = FactoryGirl.create(:user)

        visit user_path(user)

        expect(page).to have_content(user.name)
        expect(page).to have_content(user.email)
    end
end

feature "Editing Users" do
    scenario "Updating a project" do
        user = FactoryGirl.create(:user)

        visit user_path(user)
        click_link "Edit Profile"

        fill_in "Username", with: "new_username"
        click_button "Update Profile"

        expect(page).to have_content("Profile has been updated.")
    end
end

user/views/_form.html.erb

<%= form_for @user do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
    <h2><%= pluralize(@user.errors.count, 'error') %>
        prohibited this user from being saved:</h2>

        <ul>
            <% @ticket.errors.full_messages.each do |msg| %>
            <li><%= msg %></li>
            <% end %>
        </ul>
    </div>
    <% end %>

    <p>
        <%= f.label :name, "Username" %><br />
        <%= f.text_field :name %>
    </p>
    <p>
        <%= f.label :email %><br />
        <%= f.text_field :email %>
    </p>
    <p>
        <%= f.label :password, "Password" %><br />
        <%= f.text_field :password %>
    </p>
    <p>
        <%= f.label :password_confirmation %><br />
        <%= f.text_field :password_confirmation %>
    </p>
    <% if @user.new_record? %>
    <%= f.submit 'Sign up' %>
    <% else %>
    <%= f.submit "Update Profile" %>
    <% end %>

user.rb

class User < ActiveRecord::Base
    has_secure_password
end

and the error is following

1) Profile page viewing
     Failure/Error: user = FactoryGirl.create(:user)
     ArgumentError:
       Factory not registered: user
     # ./spec/features/user_profile_spec.rb:5:in `block (2 levels) in <top (required)>'

  2) Editing Users Updating a project
     Failure/Error: user = FactoryGirl.create(:user)
     ArgumentError:
       Factory not registered: user
     # ./spec/features/user_profile_spec.rb:16:in `block (2 levels) in <top (required)>'

some random text so that i can post this question to the stackoverflow forum QA editing lalalalal.

Aucun commentaire:

Enregistrer un commentaire