minitest-spec-rails 4.3.3 → 4.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  rvm:
2
2
  - 1.8.7
3
3
  - 1.9.3
4
+ - ruby-head
4
5
  gemfile:
5
6
  - gemfiles/rails30.gemfile
6
7
  - gemfiles/rails31.gemfile
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ ## v4.3.4
3
+
4
+ * Add mini_should support and talk about matchers.
5
+
6
+
2
7
  ## v4.3.3
3
8
 
4
9
  * Fix MiniTest::Unit::TestCase hack for Rails 4, ignore in Rails 3.
data/README.md CHANGED
@@ -9,13 +9,23 @@ Rails 4 was on its way to using MiniTest::Spec as the superclass for ActiveSuppo
9
9
  The minitest-spec-rails gem makes it easy to use the MiniTest::Spec DSL within your existing Rails 3 or 4 test suite. It does this by forcing ActiveSupport::TestCase to subclass MiniTest::Spec.
10
10
 
11
11
  [![Build Status](https://secure.travis-ci.org/metaskills/minitest-spec-rails.png)](http://travis-ci.org/metaskills/minitest-spec-rails)
12
+ [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/metaskills/minitest-spec-rails)
12
13
 
13
14
 
14
15
  ## Usage
15
16
 
16
17
  Existing or new Rails 3 or 4 applications that use the default Rails testing structure can simply drop in the minitest-spec-gem and start writing their tests in the new spec DSL. Since MinitTest::Spec is built on top of MiniTest::Unit, a replacement for Test::Unit, all of your existing tests will continue to work.
17
18
 
18
- This gem uses no generators and does not require you to write your tests in a new directory or file structure. It is completely different than [minitest-rails](https://github.com/blowmage/minitest-rails) which is setup more like RSpec in the way it bolts on the side of Rails. The goal of this project is to make Rails 3 or 4 applications just work as if rails-core had decided to support MiniTest::Spec. Eventually that day will come and if it does, all your tests will still work! So bundle up and get started!
19
+ ### How is this different than MiniTest::Rails?
20
+
21
+ To start off both Mike Moore (@blowmage) and I have worked together and we both LOVE MiniTest::Spec. Both projects aim to advocate MiniTest and make Rails integration as easy as possible. However, there are a few key differences in our projects. Some of these differences may go away in time too. As always, choose the tool you think fits your needs. So how, is minitest-spec-rails different than [minitest-rails](https://github.com/blowmage/minitest-rails)?
22
+
23
+ * We aim to leverage existing Rails test directories and files!
24
+ * No special test helper and/or generators.
25
+ * Easy migration path for existing Rails applications.
26
+ * How we go about freedom patching Rails.
27
+
28
+ So the goal of this project is to make Rails 3 or 4 applications just work as if rails-core had decided to support MiniTest::Spec all along. We believe that eventually that day will come and when it does, all your tests will still work! So bundle up and get started!
19
29
 
20
30
  ```ruby
21
31
  gem 'minitest-spec-rails'
@@ -34,7 +44,7 @@ assert_equal 100, foo
34
44
  foo.must_equal 100
35
45
  ```
36
46
 
37
- All existing Rails test cases that subclass ActiveSupport::TestCase will continue to work and I personally suggest that you still use what I call the subclass convention vs the outer describe test case convention. However either will work.
47
+ All existing Rails test cases that subclass ActiveSupport::TestCase will continue to work and I personally suggest that you still **use the subclass convention** vs the outer describe test case convention. However either will work.
38
48
 
39
49
  ```ruby
40
50
  require 'test_helper'
@@ -86,6 +96,99 @@ end
86
96
  ```
87
97
 
88
98
 
99
+ ## Extras
100
+
101
+ We have baked in a few extra methods behind the scenes to minitest-spec-rails. Most directly support our needs to reflect on described classes, however, they may be useful to you too when meta-programming on top of minitest-spec-rails.
102
+
103
+ ### #described_class
104
+ The `described_class` method is available both via a class method and an instance method in any Rails test case. It is guaranteed to work despite the described level too. This allows class level macros to be build, much like Shoulda. Remember, it can only do this if you follow Rails naming conventions for your tests.
105
+
106
+ ```ruby
107
+ class UserTest < ActiveSupport::TestCase
108
+ described_class # => User(id: integer, email: string)
109
+ it 'works here' do
110
+ described_class # => User(id: integer, email: string)
111
+ end
112
+ describe 'and' do
113
+ it 'works here too' do
114
+ described_class # => User(id: integer, email: string)
115
+ end
116
+ end
117
+ end
118
+ ```
119
+
120
+ ### mini_shoulda
121
+
122
+ If you are migrating away from Shoulda, then minitest-spec-rails' mini_shoulda feature will help. To enable it, set the following configuration in your test environment file.
123
+
124
+ ```ruby
125
+ # In config/environments/test.rb
126
+ config.minitest_spec_rails.mini_shoulda = true
127
+ ```
128
+
129
+ Doing so only enables a few aliases that allow the Shoulda `context`, `should`, and `should_eventually` methods. The following code demonstrates the full features of the mini_shoulda implementation. It basically replaces the shell of [should-context](https://github.com/thoughtbot/shoulda-context) in a few lines of code.
130
+
131
+ ```ruby
132
+ class PostTests < ActiveSupport::TestCase
133
+ setup { @post = Post.create! :title => 'Test Title', :body => 'Test body' }
134
+ teardown { Post.delete_all }
135
+ should 'work' do
136
+ @post.must_be_instance_of Post
137
+ end
138
+ context 'with a user' do
139
+ should_eventually 'have a user' do
140
+ # ...
141
+ end
142
+ end
143
+ end
144
+ ```
145
+
146
+ If you are in the assertions provided by shoulda-context like `assert_same_elements`, then you may want to consider copying them [from here](https://github.com/thoughtbot/shoulda-context/blob/master/lib/shoulda/context/assertions.rb) and including them in `MiniTest::Spec` yourself. I personally recommend just replacing these assertions with something more modern. A few examples are below.
147
+
148
+ ```ruby
149
+ assert_same_elements a, b # From
150
+ a.sort.must_equal b.sort # To
151
+
152
+ assert_does_not_contain a, b # From
153
+ a.wont_include b # To
154
+ ```
155
+
156
+ ### Matchers
157
+
158
+ If matchers are your thing, I recommend the [minitest-matchers](https://github.com/zenspider/minitest-matchers) gem. For example:
159
+
160
+ ```ruby
161
+ # Basic minitest-matchers features.
162
+ describe Post do
163
+ include ValidAttribute::Method
164
+ it "must have validations" do
165
+ post = Post.new
166
+ post.must have_valid(:title).when("Good")
167
+ post.wont have_valid(:title).when("")
168
+ end
169
+ end
170
+
171
+ # Using an implicit subject.
172
+ describe Post do
173
+ subject { Post.new }
174
+ it { must have_valid(:title).when("Hello") }
175
+ it { wont have_valid(:title).when("", nil, "Bad") }
176
+ end
177
+ ```
178
+
179
+ Want more? Try out the [valid_attribute](https://github.com/bcardarella/valid_attribute) gem built on top of minitest-matchers.
180
+
181
+ ```ruby
182
+ describe User do
183
+ subject { User.new }
184
+ it { must have_valid(:email).when('test@test.com', 'test+spam@gmail.com') }
185
+ it { wont have_valid(:email).when('fail', 123) }
186
+ it { must have_valid(:name).when('TestName') }
187
+ it { wont have_valid(:name).when('Test') }
188
+ end
189
+ ```
190
+
191
+
89
192
  ## Gotchas
90
193
 
91
194
  ### Assertion Methods
@@ -135,6 +238,5 @@ $ bundle exec rake appraisal:rails32 test
135
238
  ```
136
239
 
137
240
  Our current build status is:
138
-
139
241
  [![Build Status](https://secure.travis-ci.org/metaskills/minitest-spec-rails.png)](http://travis-ci.org/metaskills/minitest-spec-rails)
140
242
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/kencollins/Repositories/minitest-spec-rails
3
3
  specs:
4
- minitest-spec-rails (4.3.2)
4
+ minitest-spec-rails (4.3.3)
5
5
  minitest (~> 4.3)
6
6
  rails (>= 3.0)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/kencollins/Repositories/minitest-spec-rails
3
3
  specs:
4
- minitest-spec-rails (4.3.2)
4
+ minitest-spec-rails (4.3.3)
5
5
  minitest (~> 4.3)
6
6
  rails (>= 3.0)
7
7
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/kencollins/Repositories/minitest-spec-rails
3
3
  specs:
4
- minitest-spec-rails (4.3.2)
4
+ minitest-spec-rails (4.3.3)
5
5
  minitest (~> 4.3)
6
6
  rails (>= 3.0)
7
7
 
@@ -0,0 +1,27 @@
1
+ module MiniTestSpecRails
2
+ module Init
3
+ module MiniShouldaBehavior
4
+
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ class << self
9
+ alias :should :it
10
+ alias :context :describe
11
+ end
12
+ extend ClassMethods
13
+ end
14
+
15
+ module ClassMethods
16
+
17
+ def should_eventually(desc)
18
+ it("should eventually #{desc}") { skip("Should eventually #{desc}") }
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+
27
+ MiniTest::Spec.send :include, MiniTestSpecRails::Init::MiniShouldaBehavior
@@ -2,6 +2,7 @@ module MiniTestSpecRails
2
2
  class Railtie < ::Rails::Railtie
3
3
 
4
4
  config.minitest_spec_rails = ActiveSupport::OrderedOptions.new
5
+ config.minitest_spec_rails.mini_shoulda = false
5
6
 
6
7
  config.before_initialize do |app|
7
8
  ActiveSupport.on_load(:action_view) do
@@ -19,6 +20,7 @@ module MiniTestSpecRails
19
20
 
20
21
  initializer 'minitest-spec-rails.after.load_active_support', :after => :load_active_support, :group => :all do |app|
21
22
  require 'minitest-spec-rails/init/active_support'
23
+ require 'minitest-spec-rails/init/mini_shoulda' if app.config.minitest_spec_rails.mini_shoulda
22
24
  end
23
25
 
24
26
  end
@@ -1,3 +1,3 @@
1
1
  module MiniTestSpecRails
2
- VERSION = "4.3.3"
2
+ VERSION = "4.3.4"
3
3
  end
@@ -0,0 +1,38 @@
1
+ require 'test_helper_dummy'
2
+
3
+ class PostTests < ActiveSupport::TestCase
4
+
5
+ i_suck_and_my_tests_are_order_dependent!
6
+
7
+ $teardown_ran = false
8
+
9
+ setup do
10
+ @post = user_post
11
+ end
12
+
13
+ teardown do
14
+ $teardown_ran = true
15
+ end
16
+
17
+ should 'setup correctly and $teardown_ran should still be false since this is the first test' do
18
+ @post.must_be_instance_of Post
19
+ $teardown_ran.must_equal false
20
+ end
21
+
22
+ should 'teardown correctly' do
23
+ $teardown_ran.must_equal true
24
+ end
25
+
26
+ should_eventually 'will be skipped' do
27
+ assert false
28
+ end
29
+
30
+ context 'level 1' do
31
+
32
+ should 'work' do
33
+ @post.must_be_instance_of Post
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,6 @@
1
+ class Post < ActiveRecord::Base
2
+
3
+ belongs_to :user
4
+
5
+
6
+ end
@@ -1,3 +1,6 @@
1
1
  class User < ActiveRecord::Base
2
2
 
3
+ has_many :posts
4
+
5
+
3
6
  end
@@ -8,11 +8,13 @@ Bundler.require :default, :development, :test
8
8
  module Dummy
9
9
  class Application < ::Rails::Application
10
10
 
11
+ # Basic Engine
11
12
  config.root = File.join __FILE__, '..'
12
13
  config.cache_store = :memory_store
13
14
  config.assets.enabled = false if Rails.version > '3.1'
14
15
  config.secret_token = '012345678901234567890123456789'
15
16
 
17
+ # Mimic Test Environment Config.
16
18
  config.whiny_nils = true if Rails.version < '4.0'
17
19
  config.consider_all_requests_local = true
18
20
  config.action_controller.perform_caching = false
@@ -30,6 +32,9 @@ module Dummy
30
32
  config.eager_load = true
31
33
  config.secret_key_base = '012345678901234567890123456789'
32
34
  end
35
+
36
+ # Custom
37
+ config.minitest_spec_rails.mini_shoulda = true
33
38
 
34
39
  end
35
40
  end
@@ -7,6 +7,7 @@ module MiniTestSpecRails
7
7
  before { setup_dummy_schema }
8
8
  let(:app) { Dummy::Application }
9
9
  let(:user_ken) { User.create! :email => 'ken@metaskills.net' }
10
+ let(:user_post) { Post.create! :title => 'Test Title', :body => 'Test body. Test body.', :user => user_ken}
10
11
  end
11
12
 
12
13
  private
@@ -17,6 +18,10 @@ module MiniTestSpecRails
17
18
  create_table :users, :force => true do |t|
18
19
  t.string :email
19
20
  end
21
+ create_table :posts, :force => true do |t|
22
+ t.string :title, :body
23
+ t.integer :user_id
24
+ end
20
25
  end
21
26
  end
22
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-spec-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.3
4
+ version: 4.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-18 00:00:00.000000000 Z
12
+ date: 2013-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -137,6 +137,7 @@ files:
137
137
  - lib/minitest-spec-rails/init/action_mailer.rb
138
138
  - lib/minitest-spec-rails/init/action_view.rb
139
139
  - lib/minitest-spec-rails/init/active_support.rb
140
+ - lib/minitest-spec-rails/init/mini_shoulda.rb
140
141
  - lib/minitest-spec-rails/railtie.rb
141
142
  - lib/minitest-spec-rails/util.rb
142
143
  - lib/minitest-spec-rails/version.rb
@@ -149,12 +150,14 @@ files:
149
150
  - test/cases/action_mailer_test.rb
150
151
  - test/cases/action_view_test.rb
151
152
  - test/cases/active_support_test.rb
153
+ - test/cases/mini_shoulda_test.rb
152
154
  - test/cases/minitest_spec_rails_test.rb
153
155
  - test/dummy_app/app/controllers/application_controller.rb
154
156
  - test/dummy_app/app/controllers/users_controller.rb
155
157
  - test/dummy_app/app/helpers/application_helper.rb
156
158
  - test/dummy_app/app/helpers/users_helper.rb
157
159
  - test/dummy_app/app/mailers/user_mailer.rb
160
+ - test/dummy_app/app/models/post.rb
158
161
  - test/dummy_app/app/models/user.rb
159
162
  - test/dummy_app/app/views/users/index.html.erb
160
163
  - test/dummy_app/config/database.yml
@@ -185,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
185
188
  version: '0'
186
189
  segments:
187
190
  - 0
188
- hash: -310174248579314856
191
+ hash: 1500693276380796618
189
192
  required_rubygems_version: !ruby/object:Gem::Requirement
190
193
  none: false
191
194
  requirements:
@@ -194,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
197
  version: '0'
195
198
  segments:
196
199
  - 0
197
- hash: -310174248579314856
200
+ hash: 1500693276380796618
198
201
  requirements: []
199
202
  rubyforge_project:
200
203
  rubygems_version: 1.8.24
@@ -207,12 +210,14 @@ test_files:
207
210
  - test/cases/action_mailer_test.rb
208
211
  - test/cases/action_view_test.rb
209
212
  - test/cases/active_support_test.rb
213
+ - test/cases/mini_shoulda_test.rb
210
214
  - test/cases/minitest_spec_rails_test.rb
211
215
  - test/dummy_app/app/controllers/application_controller.rb
212
216
  - test/dummy_app/app/controllers/users_controller.rb
213
217
  - test/dummy_app/app/helpers/application_helper.rb
214
218
  - test/dummy_app/app/helpers/users_helper.rb
215
219
  - test/dummy_app/app/mailers/user_mailer.rb
220
+ - test/dummy_app/app/models/post.rb
216
221
  - test/dummy_app/app/models/user.rb
217
222
  - test/dummy_app/app/views/users/index.html.erb
218
223
  - test/dummy_app/config/database.yml