Permalink
Browse files

speeding specs with timecop, and removing duplicates

  • Loading branch information...
1 parent 5971a6d commit 694e3fadc128469f60ca1afa8e41df658110f3fe @NoamB committed Apr 20, 2011
@@ -9,5 +9,5 @@ group :development, :test do
gem 'rspec-rails'
gem 'ruby-debug19'
gem 'simplecov', '>= 0.3.8', :require => false # Will install simplecov-html as a dependency
- gem 'spork', '~> 0.9.0.rc'
+ gem 'timecop'
end
@@ -40,7 +40,7 @@ GEM
activemodel (= 3.0.3)
activesupport (= 3.0.3)
activesupport (3.0.3)
- addressable (2.2.4)
+ addressable (2.2.5)
archive-tar-minitar (0.5.2)
arel (2.0.6)
bcrypt-ruby (2.1.4)
@@ -49,7 +49,7 @@ GEM
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
- faraday (0.5.5)
+ faraday (0.6.1)
addressable (~> 2.2.4)
multipart-post (~> 1.1.0)
rack (< 2, >= 1.1.0)
@@ -66,8 +66,8 @@ GEM
multi_json (0.0.5)
multipart-post (1.1.0)
oauth (0.4.4)
- oauth2 (0.1.1)
- faraday (~> 0.5.0)
+ oauth2 (0.4.0)
+ faraday (~> 0.6.0)
multi_json (~> 0.0.4)
polyglot (0.3.1)
rack (1.2.1)
@@ -115,9 +115,9 @@ GEM
simplecov (0.3.9)
simplecov-html (>= 0.3.7)
simplecov-html (0.3.9)
- spork (0.9.0.rc3)
sqlite3-ruby (1.3.2)
thor (0.14.6)
+ timecop (0.3.5)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.23)
@@ -132,5 +132,5 @@ DEPENDENCIES
ruby-debug19
simplecov (>= 0.3.8)
sorcery (= 0.3.1)!
- spork (~> 0.9.0.rc)
sqlite3-ruby
+ timecop
@@ -19,6 +19,7 @@
after(:each) do
Sorcery::Controller::Config.reset!
sorcery_controller_property_set(:user_class, User)
+ Timecop.return
end
it "should count login retries" do
@@ -46,7 +47,7 @@
get :test_login, :username => 'gizmo', :password => 'blabla'
get :test_login, :username => 'gizmo', :password => 'blabla'
User.find_by_username('gizmo').lock_expires_at.should_not be_nil
- sleep 0.3
+ Timecop.travel(Time.now + 0.3)
get :test_login, :username => 'gizmo', :password => 'blabla'
User.find_by_username('gizmo').lock_expires_at.should be_nil
end
@@ -57,7 +58,7 @@
get :test_login, :username => 'gizmo', :password => 'blabla'
get :test_login, :username => 'gizmo', :password => 'blabla'
unlock_date = User.find_by_username('gizmo').lock_expires_at
- sleep 1
+ Timecop.travel(Time.now + 1)
get :test_login, :username => 'gizmo', :password => 'blabla'
User.find_by_username('gizmo').lock_expires_at.to_s.should == unlock_date.to_s
end
@@ -39,7 +39,8 @@ def stub_all_oauth2_requests!
create_new_user
get :login_at_test2
response.should be_a_redirect
- response.should redirect_to("http://myapi.com/oauth/authorize?client_id=key&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&type=web_server")
+ #response.should redirect_to("http://myapi.com/oauth/authorize?client_id=key&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&type=web_server")
+ response.should redirect_to("http://myapi.com/oauth/authorize?client_id=key&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&response_type=code")
end
it "'login_from' logins if user exists" do
@@ -10,6 +10,10 @@
create_new_user
end
+ after(:each) do
+ Timecop.return
+ end
+
it "should not reset session before session timeout" do
login_user
get :test_should_be_logged_in
@@ -19,7 +23,7 @@
it "should reset session after session timeout" do
login_user
- sleep 0.6
+ Timecop.travel(Time.now+0.6)
get :test_should_be_logged_in
session[:user_id].should be_nil
response.should be_a_redirect
@@ -28,10 +32,10 @@
it "with 'session_timeout_from_last_action' should not logout if there was activity" do
sorcery_controller_property_set(:session_timeout_from_last_action, true)
get :test_login, :username => 'gizmo', :password => 'secret'
- sleep 0.3
+ Timecop.travel(Time.now+0.3)
get :test_should_be_logged_in
session[:user_id].should_not be_nil
- sleep 0.3
+ Timecop.travel(Time.now+0.3)
get :test_should_be_logged_in
session[:user_id].should_not be_nil
response.should be_a_success
@@ -40,7 +44,7 @@
it "with 'session_timeout_from_last_action' should logout if there was no activity" do
sorcery_controller_property_set(:session_timeout_from_last_action, true)
get :test_login, :username => 'gizmo', :password => 'secret'
- sleep 0.6
+ Timecop.travel(Time.now+0.6)
get :test_should_be_logged_in
session[:user_id].should be_nil
response.should be_a_redirect
@@ -0,0 +1,3 @@
+--colour
+--format progress
+--profile
@@ -1,62 +1,53 @@
$: << File.join(File.dirname(__FILE__), '..', '..', 'lib' )
-require 'simplecov'
-SimpleCov.root File.join(File.dirname(__FILE__), "..", "..", "app_root" )
-SimpleCov.start do
- add_filter "/config/"
-
- add_group 'Controllers', 'app/controllers'
- add_group 'Models', 'app/models'
- add_group 'Helpers', 'app/helpers'
- add_group 'Libraries', 'lib'
- add_group 'Plugins', 'vendor/plugins'
- add_group 'Migrations', 'db/migrate'
-end
-
-require 'spork'
-
-Spork.prefork do
- # Set the default environment to sqlite3's in_memory database
- ENV['RAILS_ENV'] ||= 'in_memory'
- ENV['RAILS_ROOT'] = 'app_root'
-
- # Load the Rails environment and testing framework
- require "#{File.dirname(__FILE__)}/../config/environment"
- #require "#{File.dirname(__FILE__)}/../../init" # for plugins
- require 'rspec/rails'
-
- RSpec.configure do |config|
- config.use_transactional_fixtures = true
- config.use_instantiated_fixtures = false
- config.include RSpec::Rails::ControllerExampleGroup, :example_group => { :file_path => /controller(.)*_spec.rb$/ }
-
- config.before(:suite) do
- ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/core")
- end
-
- config.after(:suite) do
- ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/core")
- end
+# require 'simplecov'
+# SimpleCov.root File.join(File.dirname(__FILE__), "..", "..", "app_root" )
+# SimpleCov.start do
+# add_filter "/config/"
+#
+# add_group 'Controllers', 'app/controllers'
+# add_group 'Models', 'app/models'
+# add_group 'Helpers', 'app/helpers'
+# add_group 'Libraries', 'lib'
+# add_group 'Plugins', 'vendor/plugins'
+# add_group 'Migrations', 'db/migrate'
+# end
+
+require 'timecop'
+# Set the default environment to sqlite3's in_memory database
+ENV['RAILS_ENV'] ||= 'in_memory'
+ENV['RAILS_ROOT'] = 'app_root'
+
+# Load the Rails environment and testing framework
+require "#{File.dirname(__FILE__)}/../config/environment"
+require 'rspec/rails'
+
+RSpec.configure do |config|
+ config.use_transactional_fixtures = true
+ config.use_instantiated_fixtures = false
+ config.include RSpec::Rails::ControllerExampleGroup, :example_group => { :file_path => /controller(.)*_spec.rb$/ }
+
+ config.before(:suite) do
+ ActiveRecord::Migrator.migrate("#{Rails.root}/db/migrate/core")
end
-
- #----------------------------------------------------------------
- # needed when running individual specs
- require File.join(File.dirname(__FILE__), '..','app','models','user')
- require File.join(File.dirname(__FILE__), '..','app','models','authentication')
-
- class TestUser < ActiveRecord::Base
- activate_sorcery!
+
+ config.after(:suite) do
+ ActiveRecord::Migrator.rollback("#{Rails.root}/db/migrate/core")
end
+end
- class TestMailer < ActionMailer::Base
+#----------------------------------------------------------------
+# needed when running individual specs
+require File.join(File.dirname(__FILE__), '..','app','models','user')
+require File.join(File.dirname(__FILE__), '..','app','models','authentication')
+
+class TestUser < ActiveRecord::Base
+ activate_sorcery!
+end
+
+class TestMailer < ActionMailer::Base
- end
-
- include ::Sorcery::TestHelpers
- include ::Sorcery::TestHelpers::Rails
-
end
-Spork.each_run do
- # This code will be run each time you run your specs.
-end
+include ::Sorcery::TestHelpers
+include ::Sorcery::TestHelpers::Rails
@@ -150,6 +150,10 @@
sorcery_reload!([:user_activation], :user_activation_mailer => ::SorceryMailer)
end
+ after(:each) do
+ Timecop.return
+ end
+
it "load_from_activation_token should return user when token is found" do
create_new_user
User.load_from_activation_token(@user.activation_token).should == @user
@@ -169,7 +173,7 @@
it "load_from_activation_token should NOT return user when token is found and expired" do
sorcery_model_property_set(:activation_token_expiration_period, 0.1)
create_new_user
- sleep 0.5
+ Timecop.travel(Time.now+0.5)
User.load_from_activation_token(@user.activation_token).should == nil
end
@@ -76,7 +76,11 @@
before(:each) do
User.delete_all
end
-
+
+ after(:each) do
+ Timecop.return
+ end
+
it "load_from_reset_password_token should return user when token is found" do
create_new_user
@user.deliver_reset_password_instructions!
@@ -100,7 +104,7 @@
create_new_user
sorcery_model_property_set(:reset_password_expiration_period, 0.1)
@user.deliver_reset_password_instructions!
- sleep 0.5
+ Timecop.travel(Time.now+0.5)
User.load_from_reset_password_token(@user.reset_password_token).should == nil
end
@@ -164,7 +168,7 @@
old_size = ActionMailer::Base.deliveries.size
@user.deliver_reset_password_instructions!
ActionMailer::Base.deliveries.size.should == old_size + 1
- sleep 0.5
+ Timecop.travel(Time.now+0.5)
@user.deliver_reset_password_instructions!
ActionMailer::Base.deliveries.size.should == old_size + 2
end
@@ -8,5 +8,5 @@ group :development, :test do
gem 'rspec'
gem 'ruby-debug19'
gem 'simplecov', '>= 0.3.8', :require => false # Will install simplecov-html as a dependency
- gem 'spork', '~> 0.9.0.rc'
+ gem 'timecop'
end
@@ -40,7 +40,7 @@ GEM
activemodel (= 3.0.3)
activesupport (= 3.0.3)
activesupport (3.0.3)
- addressable (2.2.4)
+ addressable (2.2.5)
archive-tar-minitar (0.5.2)
arel (2.0.7)
bcrypt-ruby (2.1.4)
@@ -49,7 +49,7 @@ GEM
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
- faraday (0.5.5)
+ faraday (0.6.1)
addressable (~> 2.2.4)
multipart-post (~> 1.1.0)
rack (< 2, >= 1.1.0)
@@ -66,8 +66,8 @@ GEM
multi_json (0.0.5)
multipart-post (1.1.0)
oauth (0.4.4)
- oauth2 (0.1.1)
- faraday (~> 0.5.0)
+ oauth2 (0.4.0)
+ faraday (~> 0.6.0)
multi_json (~> 0.0.4)
polyglot (0.3.1)
rack (1.2.1)
@@ -113,10 +113,10 @@ GEM
sinatra (1.2.0)
rack (~> 1.1)
tilt (< 2.0, >= 1.2.2)
- spork (0.9.0.rc3)
sqlite3-ruby (1.3.2)
thor (0.14.6)
tilt (1.2.2)
+ timecop (0.3.5)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.24)
@@ -130,5 +130,5 @@ DEPENDENCIES
simplecov (>= 0.3.8)
sinatra (>= 1.2.0)
sorcery (= 0.3.1)!
- spork (~> 0.9.0.rc)
sqlite3-ruby
+ timecop
@@ -23,6 +23,7 @@
Sorcery::Controller::Config.reset!
sorcery_controller_property_set(:user_class, User)
User.delete_all
+ Timecop.return
end
it "should count login retries" do
@@ -50,7 +51,7 @@
get "/test_login", :username => 'gizmo', :password => 'blabla'
get "/test_login", :username => 'gizmo', :password => 'blabla'
User.find_by_username('gizmo').lock_expires_at.should_not be_nil
- sleep 0.3
+ Timecop.travel(Time.now+0.3)
get "/test_login", :username => 'gizmo', :password => 'blabla'
User.find_by_username('gizmo').lock_expires_at.should be_nil
end
@@ -61,7 +62,7 @@
get "/test_login", :username => 'gizmo', :password => 'blabla'
get "/test_login", :username => 'gizmo', :password => 'blabla'
unlock_date = User.find_by_username('gizmo').lock_expires_at
- sleep 1
+ Timecop.travel(Time.now+1)
get "/test_login", :username => 'gizmo', :password => 'blabla'
User.find_by_username('gizmo').lock_expires_at.to_s.should == unlock_date.to_s
end
@@ -39,7 +39,8 @@ def stub_all_oauth2_requests!
create_new_user
get "/login_at_test2"
last_response.should be_a_redirect
- last_response.should redirect_to("http://myapi.com/oauth/authorize?client_id=key&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&type=web_server")
+ #last_response.should redirect_to("http://myapi.com/oauth/authorize?client_id=key&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&type=web_server")
+ last_response.should redirect_to("http://myapi.com/oauth/authorize?client_id=key&redirect_uri=http%3A%2F%2Fblabla.com&scope=email%2Coffline_access&response_type=code")
end
it "'login_from' logins if user exists" do
Oops, something went wrong.

0 comments on commit 694e3fa

Please sign in to comment.