Rails rails3 版本 rspec 测试

Unknow user · January 09, 2013 · Last by blacktulip replied at January 09, 2013 · 2190 hits

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

You need to Sign in before reply, if you don't have an account, please Sign up first.