是否可以在 rspec 中测试复数功能?
let(:schedule) { FactoryGirl.create(:schedule) }
Failure/Error: it { should have_selector('h1', text: pluralize(Schedule.count.to_s, "schedule")) }
NoMethodError:
undefined method `pluralize' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0xb607068c>
答案:(正如下面 Eric C 所指出的)
describe SchedulesHelper do
describe "pluralize schedule" do
if(Schedule.count > 0)
it { pluralize(1, "schedule").should == "1 schedule" }
else
it { pluralize(0, "schedule").should == "0 schedules" }
end
end
end