0
votes

When run poll_spec.rb, error - ArgumentError: Factory not registered: vote_option

factories.rb:

   FactoryGirl.define do
  factory :user do
    email "[email protected]"
    password "foobarrr"
    password_confirmation "foobarrr"
  end

  factory :poll do
    topic "What your name?"

    trait :vote_option1 do
      association :vote_option, title: "Dima"
    end

    trait :vote_option2 do
      association :vote_option, title: "Sasha"
    end
  end
end

Its my test file poll_spec.rb:

  require 'rails_helper'


RSpec.describe Poll, type: :model do
  let(:user) { FactoryGirl.create(:user) }

  #subject { @poll }

  #it { should respond_to(:topic) }
  #it {should be_valid}


  describe "wrong information" do
    describe "less than or equal 1 vote option" do
      before do
        FactoryGirl.create(:poll, :vote_option1)

      end

      it { should_not be_valid }
    end
  end

end

Its gem file: ........................... group :test do gem 'capybara', '~> 2.4.4' gem 'selenium-webdriver', '~> 2.46.2' gem 'factory_girl_rails', '~> 4.5.0' end

How me fix this error?

1

1 Answers

0
votes

I think you are missing the factory for vote_option. You need to create a factory vote_option:

factory :vote_option do
  title "test"
end

Then you have the missing factory. Now youre poll factory can look like this:

factory :poll do
  topic "What your name?"
  vote_option
end