minitest-spec-rails 3.0.7 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +7 -0
  3. data/CHANGELOG.md +46 -0
  4. data/Gemfile +3 -1
  5. data/Guardfile +7 -0
  6. data/README.md +195 -41
  7. data/Rakefile +4 -6
  8. data/lib/minitest-spec-rails.rb +8 -2
  9. data/lib/minitest-spec-rails/dsl.rb +52 -0
  10. data/lib/minitest-spec-rails/init/action_controller.rb +24 -0
  11. data/lib/minitest-spec-rails/init/action_dispatch.rb +17 -0
  12. data/lib/minitest-spec-rails/init/action_mailer.rb +26 -0
  13. data/lib/minitest-spec-rails/init/action_view.rb +38 -0
  14. data/lib/minitest-spec-rails/init/active_support.rb +28 -0
  15. data/lib/minitest-spec-rails/init/mini_shoulda.rb +47 -0
  16. data/lib/minitest-spec-rails/rails.rb +7 -0
  17. data/lib/minitest-spec-rails/version.rb +1 -1
  18. data/minitest-spec-rails.gemspec +21 -16
  19. data/test/cases/action_controller_test.rb +41 -0
  20. data/test/cases/action_dispatch_test.rb +48 -0
  21. data/test/cases/action_mailer_test.rb +42 -0
  22. data/test/cases/action_view_test.rb +44 -0
  23. data/test/cases/active_support_test.rb +43 -0
  24. data/test/cases/mini_shoulda_test.rb +38 -0
  25. data/test/dummy_app/app/controllers/application_controller.rb +7 -0
  26. data/test/dummy_app/app/controllers/users_controller.rb +8 -0
  27. data/test/dummy_app/app/helpers/application_helper.rb +2 -0
  28. data/test/dummy_app/app/helpers/foos_helper.rb +5 -0
  29. data/test/dummy_app/app/helpers/users_helper.rb +9 -0
  30. data/test/dummy_app/app/models/post.rb +6 -0
  31. data/test/dummy_app/app/models/user.rb +6 -0
  32. data/test/dummy_app/app/models/user_mailer.rb +10 -0
  33. data/test/dummy_app/app/views/user_mailer/welcome.erb +1 -0
  34. data/test/dummy_app/app/views/users/index.rhtml +2 -0
  35. data/test/dummy_app/config/boot.rb +126 -0
  36. data/test/dummy_app/config/database.yml +3 -0
  37. data/test/dummy_app/config/environment.rb +12 -0
  38. data/test/dummy_app/config/environments/test.rb +28 -0
  39. data/test/dummy_app/config/initializers/new_rails_defaults.rb +15 -0
  40. data/test/dummy_app/config/routes.rb +6 -0
  41. data/test/dummy_app/db/schema.rb +0 -0
  42. data/test/dummy_app/init.rb +13 -0
  43. data/test/dummy_app/log/.keep +0 -0
  44. data/test/dummy_app/public/.htaccess +40 -0
  45. data/test/dummy_app/public/404.html +30 -0
  46. data/test/dummy_app/public/422.html +30 -0
  47. data/test/dummy_app/public/500.html +30 -0
  48. data/test/dummy_app/script/console +3 -0
  49. data/test/dummy_app/script/generate +3 -0
  50. data/test/dummy_tests/application_controller_test.rb +93 -0
  51. data/test/dummy_tests/foo_helper_test.rb +12 -0
  52. data/test/dummy_tests/integration_test.rb +30 -0
  53. data/test/dummy_tests/user_mailer_test.rb +91 -0
  54. data/test/dummy_tests/user_test.rb +72 -0
  55. data/test/dummy_tests/users_controller_test.rb +23 -0
  56. data/test/dummy_tests/users_helper_test.rb +81 -0
  57. data/test/support/minitest.rb +7 -0
  58. data/test/support/shared_test_case_behavior.rb +30 -0
  59. data/test/test_helper.rb +12 -0
  60. data/test/test_helper_dummy.rb +8 -0
  61. metadata +238 -63
  62. data/lib/minitest-spec-rails/test_case.rb +0 -33
  63. data/lib/test/unit.rb +0 -9
  64. data/lib/test/unit/assertions.rb +0 -7
  65. data/lib/test/unit/testcase.rb +0 -23
@@ -0,0 +1,7 @@
1
+ class ApplicationController < ActionController::Base
2
+
3
+ def index
4
+ render :text => 'Rendered MiniTest::Spec', :layout => false
5
+ end
6
+
7
+ end
@@ -0,0 +1,8 @@
1
+ class UsersController < ApplicationController
2
+
3
+ def index
4
+ @users = User.all
5
+ render :layout => false
6
+ end
7
+
8
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,5 @@
1
+ module FoosHelper
2
+ def passes
3
+ true
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module UsersHelper
2
+
3
+ def render_users_list(users)
4
+ content_tag :ul do
5
+ users.map{ |user| content_tag :li, user.email }.join.html_safe
6
+ end
7
+ end
8
+
9
+ end
@@ -0,0 +1,6 @@
1
+ class Post < ActiveRecord::Base
2
+
3
+ belongs_to :user
4
+
5
+
6
+ end
@@ -0,0 +1,6 @@
1
+ class User < ActiveRecord::Base
2
+
3
+ has_many :posts
4
+
5
+
6
+ end
@@ -0,0 +1,10 @@
1
+ class UserMailer < ActionMailer::Base
2
+
3
+ def welcome(user)
4
+ recipients user.email
5
+ from 'rails@minitest.spec'
6
+ subject 'Welcome'
7
+ body :user => user
8
+ end
9
+
10
+ end
@@ -0,0 +1 @@
1
+ Welcome to MiniTest::Spec <%= @user.email %>!
@@ -0,0 +1,2 @@
1
+ <h1>All <%= @users.size %> Users</h1>
2
+ <%= render_users_list(@users) %>
@@ -0,0 +1,126 @@
1
+ # Don't change this file!
2
+ # Configure your app in config/environment.rb and config/environments/*.rb
3
+
4
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
+
6
+ module Rails
7
+ class << self
8
+ def boot!
9
+ unless booted?
10
+ preinitialize
11
+ pick_boot.run
12
+ end
13
+ end
14
+
15
+ def booted?
16
+ defined? Rails::Initializer
17
+ end
18
+
19
+ def pick_boot
20
+ (vendor_rails? ? VendorBoot : GemBoot).new
21
+ end
22
+
23
+ def vendor_rails?
24
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
25
+ end
26
+
27
+ def preinitialize
28
+ load(preinitializer_path) if File.exist?(preinitializer_path)
29
+ end
30
+
31
+ def preinitializer_path
32
+ "#{RAILS_ROOT}/config/preinitializer.rb"
33
+ end
34
+ end
35
+
36
+ class Boot
37
+ def run
38
+ load_initializer
39
+ Rails::Initializer.run(:set_load_path)
40
+ end
41
+ end
42
+
43
+ class VendorBoot < Boot
44
+ def load_initializer
45
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
+ Rails::Initializer.run(:install_gem_spec_stubs)
47
+ Rails::GemDependency.add_frozen_gem_path
48
+ end
49
+ end
50
+
51
+ class GemBoot < Boot
52
+ def load_initializer
53
+ self.class.load_rubygems
54
+ load_rails_gem
55
+ require 'initializer'
56
+ end
57
+
58
+ def load_rails_gem
59
+ if version = self.class.gem_version
60
+ gem 'rails', version
61
+ else
62
+ gem 'rails'
63
+ end
64
+ rescue Gem::LoadError => load_error
65
+ if load_error.message =~ /Could not find RubyGem rails/
66
+ STDERR.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
67
+ exit 1
68
+ else
69
+ raise
70
+ end
71
+ end
72
+
73
+ class << self
74
+ def rubygems_version
75
+ Gem::RubyGemsVersion rescue nil
76
+ end
77
+
78
+ def gem_version
79
+ if defined? RAILS_GEM_VERSION
80
+ RAILS_GEM_VERSION
81
+ elsif ENV.include?('RAILS_GEM_VERSION')
82
+ ENV['RAILS_GEM_VERSION']
83
+ else
84
+ parse_gem_version(read_environment_rb)
85
+ end
86
+ end
87
+
88
+ def load_rubygems
89
+ min_version = '1.3.2'
90
+ require 'rubygems'
91
+ unless rubygems_version >= min_version
92
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
93
+ exit 1
94
+ end
95
+
96
+ rescue LoadError
97
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
98
+ exit 1
99
+ end
100
+
101
+ def parse_gem_version(text)
102
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
103
+ end
104
+
105
+ private
106
+ def read_environment_rb
107
+ File.read("#{RAILS_ROOT}/config/environment.rb")
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ class Rails::Boot
114
+ def run
115
+ load_initializer
116
+ Rails::Initializer.class_eval do
117
+ def load_gems
118
+ @bundler_loaded ||= Bundler.require :default, Rails.env
119
+ end
120
+ end
121
+ Rails::Initializer.run(:set_load_path)
122
+ end
123
+ end
124
+
125
+ # All that for this:
126
+ Rails.boot!
@@ -0,0 +1,3 @@
1
+ test:
2
+ :adapter: sqlite3
3
+ :database: ":memory:"
@@ -0,0 +1,12 @@
1
+ require File.join(File.dirname(__FILE__), 'boot')
2
+
3
+ Rails::Initializer.run do |config|
4
+ config.log_level = :debug
5
+ config.cache_classes = false
6
+ config.whiny_nils = true
7
+ config.action_controller.session = {
8
+ :key => 'mtsr_session',
9
+ :secret => 'ceae6058a816b1446e09ce90d8372511'
10
+ }
11
+ end
12
+
@@ -0,0 +1,28 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The test environment is used exclusively to run your application's
4
+ # test suite. You never need to work with it otherwise. Remember that
5
+ # your test database is "scratch space" for the test suite and is wiped
6
+ # and recreated between test runs. Don't rely on the data there!
7
+ config.cache_classes = true
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.action_controller.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+ config.action_view.cache_template_loading = true
16
+
17
+ # Disable request forgery protection in test environment
18
+ config.action_controller.allow_forgery_protection = false
19
+
20
+ # Tell Action Mailer not to deliver emails to the real world.
21
+ # The :test delivery method accumulates sent emails in the
22
+ # ActionMailer::Base.deliveries array.
23
+ config.action_mailer.delivery_method = :test
24
+
25
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
26
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
27
+ # like if you have constraints or database-specific column types
28
+ # config.active_record.schema_format = :sql
@@ -0,0 +1,15 @@
1
+ # These settings change the behavior of Rails 2 apps and will be defaults
2
+ # for Rails 3. You can remove this initializer when Rails 3 is released.
3
+
4
+ # Include Active Record class name as root for JSON serialized output.
5
+ ActiveRecord::Base.include_root_in_json = true
6
+
7
+ # Store the full class name (including module namespace) in STI type column.
8
+ ActiveRecord::Base.store_full_sti_class = true
9
+
10
+ # Use ISO 8601 format for JSON serialized times and dates.
11
+ ActiveSupport.use_standard_json_time_format = true
12
+
13
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
14
+ # if you're including raw json in an HTML page.
15
+ ActiveSupport.escape_html_entities_in_json = false
@@ -0,0 +1,6 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+
3
+ map.resources :users
4
+ map.root :controller => 'application'
5
+
6
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ ENV['RAILS_ENV'] = 'test'
2
+ require 'rubygems'
3
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __FILE__)
4
+ require 'bundler/setup'
5
+ require 'active_support/all'
6
+ require 'action_controller'
7
+ require 'action_view'
8
+ require 'action_mailer'
9
+ require 'test_help'
10
+ require 'rails/version'
11
+ require 'initializer'
12
+ Bundler.require :default, :development, :test
13
+ require "#{File.expand_path('../config/environment.rb', __FILE__)}"
File without changes
@@ -0,0 +1,40 @@
1
+ # General Apache options
2
+ AddHandler fastcgi-script .fcgi
3
+ AddHandler cgi-script .cgi
4
+ Options +FollowSymLinks +ExecCGI
5
+
6
+ # If you don't want Rails to look in certain directories,
7
+ # use the following rewrite rules so that Apache won't rewrite certain requests
8
+ #
9
+ # Example:
10
+ # RewriteCond %{REQUEST_URI} ^/notrails.*
11
+ # RewriteRule .* - [L]
12
+
13
+ # Redirect all requests not available on the filesystem to Rails
14
+ # By default the cgi dispatcher is used which is very slow
15
+ #
16
+ # For better performance replace the dispatcher with the fastcgi one
17
+ #
18
+ # Example:
19
+ # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
20
+ RewriteEngine On
21
+
22
+ # If your Rails application is accessed via an Alias directive,
23
+ # then you MUST also set the RewriteBase in this htaccess file.
24
+ #
25
+ # Example:
26
+ # Alias /myrailsapp /path/to/myrailsapp/public
27
+ # RewriteBase /myrailsapp
28
+
29
+ RewriteRule ^$ index.html [QSA]
30
+ RewriteRule ^([^.]+)$ $1.html [QSA]
31
+ RewriteCond %{REQUEST_FILENAME} !-f
32
+ RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
33
+
34
+ # In case Rails experiences terminal errors
35
+ # Instead of displaying this message you can supply a file here which will be rendered instead
36
+ #
37
+ # Example:
38
+ # ErrorDocument 500 /500.html
39
+
40
+ ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>The page you were looking for doesn't exist (404)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/404.html -->
25
+ <div class="dialog">
26
+ <h1>The page you were looking for doesn't exist.</h1>
27
+ <p>You may have mistyped the address or the page may have moved.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>The change you wanted was rejected (422)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/422.html -->
25
+ <div class="dialog">
26
+ <h1>The change you wanted was rejected.</h1>
27
+ <p>Maybe you tried to change something you didn't have access to.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>We're sorry, but something went wrong (500)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/500.html -->
25
+ <div class="dialog">
26
+ <h1>We're sorry, but something went wrong.</h1>
27
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/console'
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require File.dirname(__FILE__) + '/../config/boot'
3
+ require 'commands/generate'
@@ -0,0 +1,93 @@
1
+ require 'test_helper_dummy'
2
+
3
+ module ApplicationControllerTests
4
+ def self.included(klass)
5
+ klass.class_eval do
6
+
7
+ tests ApplicationController
8
+
9
+ before { get :index }
10
+
11
+ it 'works' do
12
+ get :index
13
+ @response.body.must_equal 'Rendered MiniTest::Spec'
14
+ end
15
+
16
+ it 'allows custom assertions' do
17
+ assert_template :partial => false
18
+ end
19
+
20
+ it 'can find the controller_class' do
21
+ self.class.controller_class.must_equal ApplicationController
22
+ end
23
+
24
+ it 'can access the setup ivars' do
25
+ @controller.must_be_kind_of ApplicationController
26
+ end
27
+
28
+ describe 'nested 1' do
29
+
30
+ it('works') { skip }
31
+
32
+ it 'can find the controller_class' do
33
+ self.class.controller_class.must_equal ApplicationController
34
+ end
35
+
36
+ describe 'nested 2' do
37
+
38
+ it('works') { skip }
39
+
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+
48
+ class ApplicationControllerTest < ActionController::TestCase
49
+ include ApplicationControllerTests
50
+ it 'reflects' do
51
+ describing_class.must_equal ApplicationControllerTest
52
+ described_class.must_equal ApplicationController
53
+ self.class.described_class.must_equal ApplicationController
54
+ end
55
+ describe 'level 1' do
56
+ it 'reflects' do
57
+ describing_class.must_equal ApplicationControllerTest
58
+ described_class.must_equal ApplicationController
59
+ self.class.described_class.must_equal ApplicationController
60
+ end
61
+ describe 'level 2' do
62
+ it 'reflects' do
63
+ describing_class.must_equal ApplicationControllerTest
64
+ described_class.must_equal ApplicationController
65
+ self.class.described_class.must_equal ApplicationController
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ describe ApplicationController do
72
+ include ApplicationControllerTests
73
+ it 'class reflects' do
74
+ described_class.must_equal ApplicationController
75
+ self.class.described_class.must_equal ApplicationController
76
+ end
77
+ it 'reflects' do
78
+ described_class.must_equal ApplicationController
79
+ self.class.described_class.must_equal ApplicationController
80
+ end
81
+ describe 'level 1' do
82
+ it 'reflects' do
83
+ described_class.must_equal ApplicationController
84
+ self.class.described_class.must_equal ApplicationController
85
+ end
86
+ describe 'level 2' do
87
+ it 'reflects' do
88
+ described_class.must_equal ApplicationController
89
+ self.class.described_class.must_equal ApplicationController
90
+ end
91
+ end
92
+ end
93
+ end