$ sudo gem install rspec v = 1.3.0 $ sudo gem install rspec-rails v = 1.3.2
$ script/generate rspec exists lib/tasks identical lib/tasks/rspec.rake identical script/autospec identical script/spec exists spec identical spec/rcov.opts identical spec/spec.opts identical spec/spec_helper.rb
$ sudo gem install rspec v = 1.3.0 $ sudo gem install rspec-rails v = 1.3.2
$ script/generate rspec exists lib/tasks identical lib/tasks/rspec.rake identical script/autospec identical script/spec exists spec identical spec/rcov.opts identical spec/spec.opts identical spec/spec_helper.rb
$ sudo gem install factory-girl
config.gem "factory_girl"
$ sudo gem install ZenTest $ sudo gem install autotest-rails
$ sudo gem install autotest-growl $ sudo gem install autotest-fsevent $ sudo gem install redgreen
require 'autotest/growl'
require 'autotest/fsevent'
require 'redgreen/autotest'
Autotest.add_hook :initialize do |autotest|
%w{.git .svn .hg .DS_Store ._* vendor tmp log doc}.each do |exception|
autotest.add_exception(exception)
end
end
describe "User absence or not during [start_time,end_time]" do before :each do @user = Factory(:user) end it "should return false when user not absence " do start_time = Time.utc(2010,11,9,12,0,0,0) end_time = Time.utc(2010,11,9,12,30,0) @user.absence_at(start_time,end_time).should be_false end it "should return true when user absence " do start_time = Time.utc(2010,11,9,13,0,0,0) end_time = Time.utc(2010,11,9,13,30,0) @user.absence_at(start_time,end_time).should be_ture end end
class User < ActiveRecord::Base def absence_at(start_time,end_time) return false if have_connection_or_review?(start_time,end_time) return (login_absence_at?(start_time,end_time) ? true : false) end end
before(:each) do @user = User.new end describe "method <absence_at(start_time,end_time)>" do s = Time.now e = s + 30.minutes # example one it "should be false when user have interaction or review" do @user.stub!(:have_connection_or_review?).with(s,e).and_return(true) @user.absence_at(s,e).should be_false end # example two it "should be true when user has no interaction and he no waiting at platform" do @user.stub!(:have_connection_or_review?).with(s,e).and_return(false) @user.stub!(:login_absence_at?).with(s,e).and_return(true) @user.absence_at(s,e).should be_true end # example three it "should be false when user has no interaction and he waiting at platform" do @user.stub!(:have_connection_or_review?).with(s,e).and_return(false) @user.stub!(:login_absence_at?).with(s,e).and_return(false) @user.absence_at(s,e).should be_false end end
class A < ActiveRecord::Base has_many :records def tech_finish? self.records.each do |v_a| return true if v_a.files.size == 5 end return false end end class Record < ActiveRecord::Base belongs_to :a has_files # here is a service in gem end
describe "tech_finish?" do it "should return true when A's records have five files" do record = Factory(:record) app = Factory(:a,:records=>[record]) record.stub!(:files).and_return([1,2,3,4,5]) app.tech_finish?.should == true end it "should return false when A's records have less five files" do record = Factory(:record) app = Factory(:a,:records=>[record]) record.stub!(:files).and_return([1,2,3,5]) app.tech_finish?.should == false end end
Factory.define :user_absence_example,:class => User do |user|
user.login "test"
class << user
def default_history_records
[Factory.build(:history_record,:started_at=>Time.now),
Factory.build(:history_record,:started_at=>Time.now)]
end
def default_calendars
[Factory.build(:calendar),
Factory.build(:calendar)]
end
def default_loggings
[Factory.build(:logging,:started_at=>1.days.ago),
Factory.build(:logging,:started_at=>1.days.ago)]
end
end
user.history_records {default_history_records}
user.calendars {default_calendars}
user.loggings {default_loggings}
end
before :each do @user = Factory.create(:user_absence_example) end
readonly_for_test: logings: datetime: created_at string: status integer: trainer_id
require 'rubygems'
require 'rake'
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new('spec') do |t|
t.spec_opts = ['--options', "spec/spec.opts"]
t.spec_files = FileList['spec/**/*_spec.rb']
end
Rails::Initializer.run do |config| config.gem 'rails_platform_base' end
describe "helpers" do
describe "url_of" do
before do
Rails.stub!(:env).and_return("development")
@controller = ActionController::Base.new
end
it "should get url from app's configration" do
@controller.url_of(:article, :comments, :article_id => 1).should == "http://www.idapted.com/article/articles/1/comments"
@controller.url_of(:article, :comments, :article_id => 1, :params=>{:category=>"good"}).should == "http://www.idapted.com/article/articles/1/comments?category=good"
end
end
end
describe "index action" do
it "should render report page with the current month report" do
controller.stub!(:current_user).and_return(@user)
get :index,{:flag => “test”}
response.should render_template("index")
end
end
describe "create action" do
it "should donot create new user with wrong params" do
post :create
response.should redirect_to(users_path)
flash[:notice].should == "Create Fail!"
end
it "should create a new user with right params" do
post :create, {:email => "abc@eleutian.com"}
response.should redirect_to(users_path)
flash[:notice].should == "Create Successful!"
end
end
before(:each) do
@course = Factory(:course)
end
describe "show action" do
it "should render show page when flag != assess and success" do
get :show, :id => @course.id, :flag =>"test"
response.should render_template("show")
assigns[:test_paper].should == @course
assigns[:flag].should == "test"
end
it "should render show page when flag == assess and success" do
get :show, :id => @course.id, :flag =>"assess"
response.should render_template("show")
assigns[:test_paper].should == @course
assigns[:flag].should == "assess"
end
end
describe AccountsController do
integrate_views
describe "index action" do
it "should render index.rhtml" do
get :index
response.should render_template("index")
response.should have_tag("a[href=?]",new_account_path)
response.should have_tag("a[href=?]",new_session_path)
end
end
end
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有