嘿,我第一次使用TDD和rails ......有趣的概念。絕對有用。也就是說,直到我來到這裏。當我運行我的測試,我得到:「Joe Smith」與rspec中的Joe Smith不一樣嗎?
1) User should build the full name correctly
Failure/Error: @u1.fullname.to_s.should be("#{@attr[:firstname]} #{@attr[:lastname]}")
expected Joe Smith, got "Joe Smith"
# ./spec/models/user_spec.rb:35:in `block (2 levels) in <top (required)>'
# /home/brian/.rvm/gems/[email protected]/gems/rspec-core-2.0.0.beta.18/lib/rspec/monkey/spork/test_framework/rspec.rb:4:in `run_tests'
# /home/brian/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/run_strategy/forking.rb:13:in `block in run'
# /home/brian/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/forker.rb:21:in `block in initialize'
# /home/brian/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/forker.rb:18:in `fork'
# /home/brian/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/forker.rb:18:in `initialize'
# /home/brian/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/run_strategy/forking.rb:9:in `new'
# /home/brian/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/run_strategy/forking.rb:9:in `run'
# /home/brian/.rvm/gems/[email protected]/gems/spork-0.8.4/lib/spork/server.rb:47:in `run'
其中測試是:
it 'should build the full name correctly' do
@u1.fullname.should be("#{@attr[:firstname]} #{@attr[:lastname]}")
end
和支持的代碼是:
def fullname
"#{firstname} #{lastname}"
end
所以,很顯然這工作,但什麼是與報價分數?我是否錯過了一些頭腦明顯的東西?
你有沒有理由不使用'@ u1.firstname'和'@ u1.lastname'? – theIV 2010-09-10 19:49:56