0

这是我的 work_spec.rb 文件的样子。运行该代码时出现by_letter未定义方法错误。

require 'spec_helper'
require 'factory_girl_rails'

describe Work do
  it "has a valid factory" do
    FactoryGirl.create(:work).should be_valid
  end
  it "is invalid without a last_name" do
     FactoryGirl.build((:work), last_name: nil).should be_valid
  end

  it "returns a sorted array of result that match" do
    smith = FactoryGirl.create((:work), last_name: "smith")
    jones = FactoryGirl.create((:work), last_name: "jones")
    johnson = FactoryGirl.create((:work), last_name: "johnson")

    Work.by_letter("j").should == [johnson, jones]
  end
end


Error receved while running
     Work returns a sorted array of result that match
     Failure/Error: Work.by_letter("j").should == [johnson, jones]
     NoMethodError:
     undefined method `by_letter' for #<Class:0x0000000429a708>
     # ./spec/models/work_spec.rb:17:in `block (2 levels) in <top (required)>'
4

1 回答 1

0

它失败的原因是你没有by_letterWork类中定义方法。

于 2013-02-01T19:40:34.027 回答