Rails中的RSpec具有“MyString”属性

时间:2013-01-01 15:59:49

标签: ruby-on-rails ruby rspec

我的RSpec测试不断弹出这些“MyString”属性。人们说这与固定装置有关,但我不使用它们。我删除了test目录,但问题仍然存在。我正在使用Fabrication for Factories / Fabricators。我也在使用Devise的测试助手。

这是我的控制器规范有问题:

it "allows you to see your posts" do
  sign_in Fabricate(:user)
  Fabricate(:post)
  get 'by_me'
  @posts.first.song.should eq "The Sound of Settling"
end

这是我的Post Factory / Fabricator:

Fabricator(:post) do
  song   "The Sound of Settling"
  artist "Death Cab for Cutie"
  album  "Transatlantism"
  username "foo"
end

我的用户工厂/制造商:

Fabricator(:user) do
  username "foo"
  password "password"
  password_confirmation "password"
end

这是失败的消息:

  1) PostsController allows you to see your posts
     Failure/Error: Post.first.song.should eq "The Sound of Settling"

       expected: "The Sound of Settling"
            got: "MyString"

       (compared using ==)
     # ./spec/controllers/posts_controller_spec.rb:31:in `block (2 levels) in <top (required)>'

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我不知道发生了什么,但问题已经消失了。