遵循RoR3教程 - 测试不一致

时间:2011-04-05 07:57:20

标签: ruby-on-rails-3

我正在关注Ruby on Rails 3教程,第6章。在我的目录spec/models/user_spec.rb中,我有6个测试用例(无需仔细阅读):

require 'spec_helper'

describe User do
  #pending "add some examples to (or delete) #{__FILE__}"
  before(:each) do
    @attr = { :name => "Example User", :email => "user@example.com"}
  end

  it "should creat a new instance given valid attributes" do
    User.create!(@attr)
  end

  .
  .
  .

  it "should reject invalid email addresses" do
    addresses = %w[user@foo,com user_at_foo.org example.user@foo.]
    addresses.each do |address|
      invalid_email_user = User.new(@attr.merge(:email => address))
      invalid_email_user.should_not be_valid
    end
  end

end

在控制台中,我输入$ rspec spec/models/user_spec.rb并吐出

No DRb server is running. Running in local process instead ...
*

Pending:
  User add some examples to (or delete) /Users/matthew/Desktop/rails_projects/sample_app/spec/models/user_spec.rb
    # Not Yet Implemented
    # ./spec/models/user_spec.rb:4

Finished in 0.00023 seconds
1 example, 0 failures, 1 pending

最后一行说我只有1个例子和1个待定,但我写了6个测试!这种不一致令我难以置信!没有语法错误,我正在保存文件,我在正确的目录中等等。

1 个答案:

答案 0 :(得分:0)

到目前为止最奇怪的事情(我正在使用Mac OS X和Textmate):

尽管代码,目录等正确但CMD + S或文件 - >保存根本没有保存文件。我一直在通过命令行打开文件。解决方案是关闭shell并打开一个新的。