Skip to content

Instantly share code, notes, and snippets.

@MichaelTorfs
Created February 15, 2011 15:55
Show Gist options
  • Save MichaelTorfs/827690 to your computer and use it in GitHub Desktop.
Save MichaelTorfs/827690 to your computer and use it in GitHub Desktop.
Rails test performance under Windows & OSX
MacBook-Pro-van-Michael-Torfs:rake michaeltorfs$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.5.2
- RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-10
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/michaeltorfs/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
MacBook-Pro-van-Michael-Torfs:huddle michaeltorfs$ rake
(in /Users/michaeltorfs/devel/huddle)
Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
......
Finished in 0.049329 seconds.
6 tests, 6 assertions, 0 failures, 0 errors
Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
................
Finished in 0.438089 seconds.
16 tests, 28 assertions, 0 failures, 0 errors
#!/usr/bin/env ruby
# Load the test files from the command line.
ARGV.each { |f| load f unless f =~ /^-/ }
/test/test_helper.rb
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
# Add more helper methods to be used by all tests here...
def login_as_one
sign_in(users(:one))
end
def set_current_project(symbol)
@request.session[:project_id] = projects(symbol).id
end
end
class ActionController::TestCase
include Devise::TestHelpers
end
/test/functional/projects_controller_test.rb
require 'test_helper'
class ProjectsControllerTest < ActionController::TestCase
setup :login_as_one
setup do
@project = projects(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:projects)
end
test "should get new" do
get :new
assert_response :success
end
test "should create project" do
assert_difference('Project.count') do
post :create, :project => @project.attributes
end
assert_redirected_to project_path(assigns(:project))
end
test "should show project" do
get :show, :id => @project.to_param
assert_response :success
end
test "should get edit" do
get :edit, :id => @project.to_param
assert_response :success
end
test "should update project" do
put :update, :id => @project.to_param, :project => @project.attributes
assert_redirected_to project_path(assigns(:project))
end
test "should destroy project" do
assert_difference('Project.count', -1) do
delete :destroy, :id => @project.to_param
end
assert_redirected_to projects_path
end
end
/test/functional/status_reports_controller_test.rb
require 'test_helper'
class StatusReportsControllerTest < ActionController::TestCase
setup :login_as_one
setup do
@status_report = status_reports(:one)
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:status_reports)
end
test "should get new" do
get :new
assert_response :success
end
test "should create status_report" do
assert_difference('StatusReport.count') do
post :create, :status_report => @status_report.attributes
end
assert_redirected_to status_report_path(assigns(:status_report))
end
test "should show status_report" do
get :show, :id => @status_report.to_param
assert_response :success
end
test "should get edit" do
get :edit, :id => @status_report.to_param
assert_response :success
end
test "should update status_report" do
put :update, :id => @status_report.to_param, :status_report => @status_report.attributes
assert_redirected_to status_report_path(assigns(:status_report))
end
test "should destroy status_report" do
assert_difference('StatusReport.count', -1) do
delete :destroy, :id => @status_report.to_param
end
assert_redirected_to status_reports_path
end
test "creation of status report with data" do
set_current_project(:one)
assert_difference('StatusReport.count', 1) do
post :create, :status_report => {
:yesterday => "I did stuff",
:today => "I'll do stuff"
}
end
actual = assigns(:status_report)
assert_equal(projects(:one).id, actual.project.id)
assert_equal(users(:one).id, actual.user.id)
assert_equal(Date.today.to_s(:db), actual.status_date.to_s(:db))
assert_redirected_to status_report_path(actual)
end
test "redirect and logout if the user tries to snipe a user id" do
noel = User.create!(:email => "sniper@gmail.com", :password => "Banana", :password_confirmation => "Banana")
set_current_project(:one)
assert_no_difference('StatusReport.count') do
post :create, :status_report => {
:user_id => noel.id,
:yesterday => "I did stuff",
:today => "I'll do stuff"
}
end
assert_nil session[:user_id]
assert_redirected_to(new_user_session_path)
end
end
/test/unit/status_report.rb
require 'test_helper'
class StatusReportTest < ActiveSupport::TestCase
test "saving a status report saves the status date" do
actual = StatusReport.new(:today => "t", :yesterday => "y")
actual.save
assert_equal(Date.today.to_s, actual.status_date.to_s)
end
test "saving a status report that has a date doesn't override" do
actual = StatusReport.new(:today => "t", :yesterday => "y", :status_date => 10.days.ago.to_date)
actual.save
actual.reload
assert_equal(10.days.ago.to_date.to_s, actual.status_date.to_s)
end
test "a report with both blank is not valid" do
actual = StatusReport.new(:today => "", :yesterday => "")
assert !actual.valid?
end
test "a report with today blank is valid" do
actual = StatusReport.new(:today => "", :yesterday => "y")
assert actual.valid?
end
test "a report with yesterday blank is valid" do
actual = StatusReport.new(:today => "t", :yesterday => "")
assert actual.valid?
end
end
C:\Devel\huddle>gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.4.2
- RUBY VERSION: 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32]
- INSTALLATION DIRECTORY: C:/Ruby187/lib/ruby/gems/1.8
- RUBY EXECUTABLE: C:/Ruby187/bin/ruby.exe
- EXECUTABLE DIRECTORY: C:/Ruby187/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-mingw32
- GEM PATHS:
- C:/Ruby187/lib/ruby/gems/1.8
- C:/Users/Michael/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/", "http://gemcutter.org"]
- REMOTE SOURCES:
- http://gems.rubyforge.org/
- http://gemcutter.org
C:\Devel\huddle>rake
(in C:/Devel/huddle)
Loaded suite C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loa
der
Started
......
Finished in 8.209469 seconds.
6 tests, 6 assertions, 0 failures, 0 errors
Loaded suite C:/Ruby187/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loa
der
Started
................
Finished in 9.216527 seconds.
16 tests, 28 assertions, 0 failures, 0 errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment