Rails rails3 版本 rspec 测试

匿名 · 2013年01月09日 · 最后由 blacktulip 回复于 2013年01月09日 · 2195 次阅读

sell_spec.rb require 'spec_helper'

describe Sell do pending "add some examples to (or delete) #{FILE}" it "age is must a number" do sell = Sell.new sell.name="12" sell.sex="mm" sell.sex=12 sell.save end end

sell.rb class Sell < ActiveRecord::Base attr_accessible :age, :name, :sex validates_numericality_of :age, :only_integer => true, :greater_than => 0 end

where is Error???

Failures:

1) SellsController GET edit assigns the requested sell as @sell Failure/Error: sell = Sell.create! valid_attributes ActiveRecord::RecordInvalid: Validation failed: Age is not a number # ./spec/controllers/sells_controller_spec.rb:62:in `block (3 levels) in '

2) SellsController POST create with valid params redirects to the created sell Failure/Error: response.should redirect_to(Sell.last) Expected response to be a <:redirect>, but was <200> # ./spec/controllers/sells_controller_spec.rb:84:in `block (

sell.sex="mm" sell.sex=12

重复赋值给 sell.sex 了吧,后面一行是 sell.age

需要 登录 后方可回复, 如果你还没有账号请 注册新账号