From fd5747f4dc558eb9dd27c733c4b433da97e4faf0 Mon Sep 17 00:00:00 2001 From: yanxd Date: Mon, 14 Jul 2014 10:27:54 +0800 Subject: [PATCH] test 3-framework --- Gemfile | 6 ++- Gemfile.lock | 53 ++++++++++++++++++- Guardfile | 45 ++++++++++++++++ app/models/setting.rb | 2 +- .../test/test_helper.rb | 2 +- test/integration/account_test.rb | 2 +- test/integration/routing/courses_test.rb | 27 ++++++++++ .../scm/adapters/bazaar_adapter_test.rb | 2 +- .../redmine/scm/adapters/cvs_adapter_test.rb | 2 +- .../scm/adapters/darcs_adapter_test.rb | 2 +- .../redmine/scm/adapters/git_adapter_test.rb | 2 +- .../scm/adapters/mercurial_adapter_test.rb | 2 +- .../scm/adapters/subversion_adapter_test.rb | 2 +- 13 files changed, 137 insertions(+), 12 deletions(-) create mode 100644 Guardfile create mode 100644 test/integration/routing/courses_test.rb diff --git a/Gemfile b/Gemfile index 634af9683..4d9e788d8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -source 'https://rubygems.org' +source 'https://ruby.taobao.org' unless RUBY_PLATFORM =~ /w32/ # unix-like only @@ -19,6 +19,9 @@ gem 'acts-as-taggable-on', '2.4.1' group :development do gem 'better_errors', path: 'lib/better_errors' gem 'rack-mini-profiler', path: 'lib/rack-mini-profiler' + gem "guard-rails" + gem 'guard-minitest' + gem 'guard-spork' if ENV['PRY'] gem 'pry' gem 'pry-nav' @@ -26,7 +29,6 @@ group :development do end group :test do - # shoulda的版本做了改动 #gem "shoulda", "~> 3.3.2" gem "shoulda", "> 3.3.2" gem "mocha", "~> 0.13.3" diff --git a/Gemfile.lock b/Gemfile.lock index d30eb7bc4..78b643e44 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,7 +19,7 @@ PATH rails GEM - remote: https://rubygems.org/ + remote: https://ruby.taobao.org/ remote: https://rubygems.org/ specs: actionmailer (3.2.13) @@ -60,6 +60,8 @@ GEM rack-test (>= 0.5.4) selenium-webdriver (~> 2.0) xpath (~> 1.0.0) + celluloid (0.15.2) + timers (~> 1.1.0) childprocess (0.5.3) ffi (~> 1.0, >= 1.0.11) climate_control (0.0.3) @@ -77,7 +79,24 @@ GEM erubis (2.7.0) execjs (2.0.2) fastercsv (1.5.0) + ffi (1.9.3) ffi (1.9.3-x86-mingw32) + formatador (0.2.5) + guard (2.6.1) + formatador (>= 0.2.4) + listen (~> 2.7) + lumberjack (~> 1.0) + pry (>= 0.9.12) + thor (>= 0.18.1) + guard-minitest (2.3.1) + guard (~> 2.0) + minitest (>= 3.0) + guard-rails (0.5.2) + guard (~> 2.0) + guard-spork (1.5.1) + childprocess (>= 0.2.3) + guard (>= 1.1) + spork (>= 0.8.4) hike (1.2.3) htmlentities (4.3.2) i18n (0.6.1) @@ -89,16 +108,25 @@ GEM kaminari (0.16.1) actionpack (>= 3.0.0) activesupport (>= 3.0.0) + listen (2.7.9) + celluloid (>= 0.15.2) + rb-fsevent (>= 0.9.3) + rb-inotify (>= 0.9) + lumberjack (1.0.9) mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) metaclass (0.0.4) + method_source (0.8.2) mime-types (1.23) + minitest (5.4.0) mocha (0.13.3) metaclass (~> 0.0.1) multi_json (1.7.6) + mysql2 (0.3.11) mysql2 (0.3.11-x86-mingw32) net-ldap (0.3.1) + nokogiri (1.5.11) nokogiri (1.5.11-x86-mingw32) paperclip (3.5.4) activemodel (>= 3.0.0) @@ -106,6 +134,17 @@ GEM cocaine (~> 0.5.3) mime-types polyglot (0.3.3) + pry (0.9.12.6) + coderay (~> 1.0) + method_source (~> 0.8) + slop (~> 3.4) + pry (0.9.12.6-x86-mingw32) + coderay (~> 1.0) + method_source (~> 0.8) + slop (~> 3.4) + win32console (~> 1.3) + pry-nav (0.2.3) + pry (~> 0.9.10) rack (1.4.5) rack-cache (1.2) rack (>= 0.4) @@ -134,6 +173,9 @@ GEM rdoc (~> 3.4) thor (>= 0.14.6, < 2.0) rake (10.3.2) + rb-fsevent (0.9.4) + rb-inotify (0.9.5) + ffi (>= 0.5.0) rdoc (3.12.2) json (~> 1.4) rich (1.4.6) @@ -163,6 +205,8 @@ GEM shoulda-context (1.2.1) shoulda-matchers (2.6.1) activesupport (>= 3.0.0) + slop (3.5.0) + spork (0.9.2) sprockets (2.2.2) hike (~> 1.2) multi_json (~> 1.0) @@ -170,6 +214,7 @@ GEM tilt (~> 1.1, != 1.3.0) thor (0.18.1) tilt (1.4.1) + timers (1.1.0) treetop (1.4.14) polyglot polyglot (>= 0.3.1) @@ -178,6 +223,7 @@ GEM execjs (>= 0.3.0) json (>= 1.8.0) websocket (1.0.7) + win32console (1.3.2-x86-mingw32) xpath (1.0.0) nokogiri (~> 1.3) @@ -194,6 +240,9 @@ DEPENDENCIES coderay (~> 1.0.6) coffee-rails (~> 3.2.1) fastercsv (~> 1.5.0) + guard-minitest + guard-rails + guard-spork htmlentities i18n (~> 0.6.0) jquery-rails (~> 2.0.2) @@ -203,6 +252,8 @@ DEPENDENCIES net-ldap (~> 0.3.1) nokogiri (< 1.6.0) paperclip (~> 3.5.4) + pry + pry-nav rack-mini-profiler! rack-openid rails (= 3.2.13) diff --git a/Guardfile b/Guardfile new file mode 100644 index 000000000..c30f4195e --- /dev/null +++ b/Guardfile @@ -0,0 +1,45 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +guard 'rails' do + watch('Gemfile.lock') + watch(%r{^(config|lib)/.*}) +end + + +guard :minitest, :drb => true, test_folders: 'test/unit', test_file_patterns: '*_test.rb' do + # with Minitest::Unit + watch(%r{^test/(.*)\/?test_(.*)\.rb$}) + watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" } + watch(%r{^test/test_helper\.rb$}) { 'test' } + + # with Minitest::Spec + # watch(%r{^spec/(.*)_spec\.rb$}) + # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } + # watch(%r{^spec/spec_helper\.rb$}) { 'spec' } + + # Rails 4 + # watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" } + # watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' } + # watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" } + # watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" } + # watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" } + # watch(%r{^test/.+_test\.rb$}) + # watch(%r{^test/test_helper\.rb$}) { 'test' } + + # Rails < 4 + watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" } + watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" } + watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" } +end + +guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do + watch('config/application.rb') + watch('config/environment.rb') + watch('config/environments/test.rb') + watch(%r{^config/initializers/.+\.rb$}) + watch('Gemfile.lock') + watch('spec/spec_helper.rb') { :rspec } + watch('test/test_helper.rb') { :test_unit } + watch(%r{features/support/}) { :cucumber } +end diff --git a/app/models/setting.rb b/app/models/setting.rb index 583d034df..3f11ef7c2 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -163,7 +163,7 @@ class Setting < ActiveRecord::Base end # fixed domain url in development. tantantan's bug - if Rails.env.development? + if Rails.env.development? || Rails.env.test? methods.map do |m| define_singleton_method m do; nil; end if m.to_s =~ /([a-zA-Z]+_domain)$/ end diff --git a/lib/plugins/open_id_authentication/test/test_helper.rb b/lib/plugins/open_id_authentication/test/test_helper.rb index 43216e1ef..cb76ceddc 100644 --- a/lib/plugins/open_id_authentication/test/test_helper.rb +++ b/lib/plugins/open_id_authentication/test/test_helper.rb @@ -8,7 +8,7 @@ gem 'actionpack' require 'action_controller' gem 'mocha' -require 'mocha' +require 'mocha/setup' gem 'ruby-openid' require 'openid' diff --git a/test/integration/account_test.rb b/test/integration/account_test.rb index 7562bcf7c..fcb3ce4f8 100644 --- a/test/integration/account_test.rb +++ b/test/integration/account_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../test_helper', __FILE__) begin - require 'mocha' + require 'mocha/setup' rescue # Won't run some tests end diff --git a/test/integration/routing/courses_test.rb b/test/integration/routing/courses_test.rb new file mode 100644 index 000000000..5554cb03d --- /dev/null +++ b/test/integration/routing/courses_test.rb @@ -0,0 +1,27 @@ +# Redmine - project management software +# Copyright (C) 2006-2013 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../../test_helper', __FILE__) + +class RoutingProjectsTest < ActionController::IntegrationTest + def test_courses + assert_routing( + { :method => 'get', :path => "/courses" }, + { :controller => 'projects', :action => 'index' } + ) + end +end diff --git a/test/unit/lib/redmine/scm/adapters/bazaar_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/bazaar_adapter_test.rb index d69da033f..3e3f6ca88 100644 --- a/test/unit/lib/redmine/scm/adapters/bazaar_adapter_test.rb +++ b/test/unit/lib/redmine/scm/adapters/bazaar_adapter_test.rb @@ -17,7 +17,7 @@ require File.expand_path('../../../../../../test_helper', __FILE__) begin - require 'mocha' + require 'mocha/setup' class BazaarAdapterTest < ActiveSupport::TestCase REPOSITORY_PATH = Rails.root.join('tmp/test/bazaar_repository').to_s diff --git a/test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb index 6b2a804e0..cddedf871 100644 --- a/test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb +++ b/test/unit/lib/redmine/scm/adapters/cvs_adapter_test.rb @@ -17,7 +17,7 @@ require File.expand_path('../../../../../../test_helper', __FILE__) begin - require 'mocha' + require 'mocha/setup' class CvsAdapterTest < ActiveSupport::TestCase REPOSITORY_PATH = Rails.root.join('tmp/test/cvs_repository').to_s diff --git a/test/unit/lib/redmine/scm/adapters/darcs_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/darcs_adapter_test.rb index 5b689001a..f5a642689 100644 --- a/test/unit/lib/redmine/scm/adapters/darcs_adapter_test.rb +++ b/test/unit/lib/redmine/scm/adapters/darcs_adapter_test.rb @@ -17,7 +17,7 @@ require File.expand_path('../../../../../../test_helper', __FILE__) begin - require 'mocha' + require 'mocha/setup' class DarcsAdapterTest < ActiveSupport::TestCase REPOSITORY_PATH = Rails.root.join('tmp/test/darcs_repository').to_s diff --git a/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb index 946ea4bfa..443b900bf 100644 --- a/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb +++ b/test/unit/lib/redmine/scm/adapters/git_adapter_test.rb @@ -17,7 +17,7 @@ require File.expand_path('../../../../../../test_helper', __FILE__) begin - require 'mocha' + require 'mocha/setup' class GitAdapterTest < ActiveSupport::TestCase REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s diff --git a/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb index c23e7debd..ee31ff030 100644 --- a/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb +++ b/test/unit/lib/redmine/scm/adapters/mercurial_adapter_test.rb @@ -17,7 +17,7 @@ require File.expand_path('../../../../../../test_helper', __FILE__) begin - require 'mocha' + require 'mocha/setup' class MercurialAdapterTest < ActiveSupport::TestCase HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_DIR diff --git a/test/unit/lib/redmine/scm/adapters/subversion_adapter_test.rb b/test/unit/lib/redmine/scm/adapters/subversion_adapter_test.rb index 8bf08f011..dba1a6d43 100644 --- a/test/unit/lib/redmine/scm/adapters/subversion_adapter_test.rb +++ b/test/unit/lib/redmine/scm/adapters/subversion_adapter_test.rb @@ -18,7 +18,7 @@ require File.expand_path('../../../../../../test_helper', __FILE__) begin - require 'mocha' + require 'mocha/setup' class SubversionAdapterTest < ActiveSupport::TestCase