0

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.

4

1 回答 1

2

这里有几个问题:

  1. 不要使用别名,因为它是保留字
  2. 您正在传递aliases到块而不是alias
于 2013-06-03T17:07:07.630 回答