我是Rspecs中的新成員,所以我寫下的代碼是正確的...我使用了簡單的Rspec。目前Rspec正確運行,但客戶需要做什麼修改?
如果有人可以看看我的代碼,並幫助我走出這將不勝感激....在rails中編寫rspecs的正確方法
require 'spec_helper'
require 'rails_helper'
describe User do
describe "fails" do
it "to create without email" do
user = User.create(:first_name => "test", :last_name => "test",:email => "")
user.errors.messages[:email][0].should eq "can't be blank"
end
end
describe "fails" do
it "to create without data" do
user = User.create(:first_name => "", :last_name => "", :email => "", :status => "")
user.errors.messages[:email][0].should eq "can't be blank"
end
end
describe "fail" do
it "to create without a valid email" do
user = User.create(:first_name => "", :last_name => "", :email => "[email protected]", :status => "")
expect(user).to be_valid, lambda { "expected valid email" }
end
end
describe "pass" do
it "to supports 2 letter domain qualifiers" do
user = User.create(:first_name => "", :last_name => "", :email => "[email protected]", :status => "")
user.save!
end
end
describe "pass" do
it "to supports 4 letter domain qualifiers" do
user = User.create(:first_name => "", :last_name => "", :email => "[email protected]", :status => "")
user.save!
end
end
end
describe "pass" do
it "to supports 4 and more letter domain qualifiers" do
user = User.create(:first_name => "", :last_name => "", :email => "[email protected]", :status => "")
user.save!
end
end
describe "pass" do
it "to without first name" do
user = User.new
user.first_name = ""
user.last_name = "Test"
user.status = "active"
user.email = "[email protected]"
user.save!
end
end
describe "pass" do
it "to without last name" do
user = User.new
user.first_name = "Test"
user.last_name = ""
user.status = "active"
user.email = "[email protected]"
user.save!
end
end
describe "pass" do
it "to without status" do
user = User.new
user.first_name = "Test"
user.last_name = "Test"
user.status = ""
user.email = "[email protected]"
user.save!
end
end
describe "pass" do
it "to create new record without first name, last name and status" do
user = User.create(:first_name => "", :last_name => "", :email => "[email protected]", :status => "")
user.save!
end
end
describe "pass" do
it "to create new record with all parameter" do
user = User.new
user.first_name = "Test"
user.last_name = "Test"
user.status = "active"
user.email = "[email protected]"
user.save!
end
end
describe "pass" do
it "to update record" do
user = User.find_by_id(1127)
user.first_name = "Test"
user.last_name = "Test"
user.status = "active"
user.email = "[email protected]"
user.save!
end
end
哪裏都是你的測試,你可以寫
? :) – fabersky
非常感謝你@fabersky ...我也是新的堆棧... :)謝謝你的正確編輯... –