user2448588
user2448588

Reputation: 3

Rspec test not passing because of model name?

I'm testing my User model and they can have many aliases:

describe User do
  describe "alias associations" do

    before { @user.save }
    let!(:first_alias) do
      FactoryGirl.create(:alias, user: @user, created_at: 1.day.ago)
    end

    let!(:second_alias) do
      FactoryGirl.create(:alias, user: @user, created_at: 1.hour.ago)
    end

    it "User should have many aliases" do
      @user.aliases.should == [first_alias, second_alias]
    end

    it "should destroy associated aliases" do
      aliases = @user.aliases.dup
      @user.destroy
      aliases.should be_empty

      aliases.each do |aliases|
        Alias.find_by_id(alias.id).should be_nil
      end

    end
  end
end

My Rspec test is throwing me a loop though. I have a model named Alias and it's giving me this error:

 syntax error, unexpected keyword_alias, expecting ')' (SyntaxError)
        Alias.find_by_id(alias.id).should be_nil

When I do alias.id it's considered to be a problem.

Why am I getting this error? Is it because of my use of Alias as a model? Changing it to something else gets the test to run.

Upvotes: 0

Views: 59

Answers (1)

phoet
phoet

Reputation: 18835

there are several problems here:

  1. don't use alias, because it's a reserved word
  2. you are passing aliases to the block instead of alias

Upvotes: 2

Related Questions