minitest_rails_tools 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 768e96fcb402c95ffda7b9fbc71f5a57d3bd780d
4
+ data.tar.gz: 8467239b6a4bcbee159e07fcf7292f9460dd14c4
5
+ SHA512:
6
+ metadata.gz: e922e9fbf107620c241ce39281e6aeb970a7cbbb7efbab9d67896998b38354cd602fa2a696ea6e735dcbb2ba9f348deff699820cff71fc1c3fc1b68ec0b5df36
7
+ data.tar.gz: ca612691e7ebf063774fc7f6c12bca04364ea1401616a59e65d874a123fb9219fe27aa4e307478879c6503a59464ab07267e60eb3e7e11a20d737acea69456e2
data/LICENSE CHANGED
@@ -1,3 +1,5 @@
1
+ The MIT License (MIT)
2
+
1
3
  Copyright © 2013 SUSE
2
4
 
3
5
  Author: Dominik Bamberger ( bamboo [at] suse.com)
data/README.md CHANGED
@@ -3,64 +3,126 @@
3
3
 
4
4
  This is a collection of little helpers to make working with Rails and Minitest a bit easier.
5
5
 
6
- _NOTE: This is a work in progress. I'm using this gem in two of my applications and I'm going to continue to add stuff to it, as well as fixing bugs._
7
-
8
6
 
9
7
  ## Installation
10
8
 
11
9
  To install this gem, just put it in your `Gemfile`:
12
10
 
13
11
  group :test do
14
- gem 'minitest', :require => false
15
12
  gem 'minitest_rails_tools', :require => false
16
13
  end
17
14
 
18
15
  Afterwards require it in your `test_helper.rb`:
19
16
 
20
- require 'minitest/autorun'
21
17
  require 'minitest_rails_tools'
22
18
 
23
- Alternatively, you could also just require certain parts of the tools:
19
+ Alternatively, you could also just require certain parts of the tools.
20
+ See the respective section for the command to add only a specific part.
21
+
22
+ In order to get rid of TestUnit, just open your `application.rb` and change
23
+ the following lines:
24
+
25
+ # Pick the frameworks you want:
26
+ # require 'rails/all'
27
+ require "active_record/railtie"
28
+ require "action_controller/railtie"
29
+ require "action_mailer/railtie"
30
+ require "active_resource/railtie"
31
+ require "sprockets/railtie"
32
+ # require "rails/test_unit/railtie"
24
33
 
25
- require 'minitest/autorun'
26
- require 'association_matchers'
27
- require 'validation_matchers'
28
- require 'helper_extension'
34
+ For generators to use MiniTest instead of TestUnit (additionally) change this:
35
+
36
+ config.generators do |g|
37
+ g.test_framework :mini_test, :spec => true, :fixture => true
38
+ end
29
39
 
30
40
 
31
41
  ## Tools
32
42
 
43
+ ### Application Integration
44
+
45
+ Adds Rails' routes URL helpers and registers ControllerSpecs. Just put the
46
+ controller name into the describe title:
47
+
48
+ describe 'FooController' do
49
+
50
+ let(:bam) { 42 }
51
+
52
+ it 'does generic stuff' do
53
+ get :bar, :zer => bam
54
+ response.message.must_equal("OK")
55
+ end
56
+
57
+ end
58
+
59
+ This functionality is separately available by adding:
60
+
61
+ require 'minitest_rails_tools/application_integration'
62
+
63
+
33
64
  ### Association Matchers
34
65
 
35
66
  This allows you to test standard Rails associations in your tests:
36
67
 
37
68
  subject { FactoryGirl.create :foo }
38
-
69
+
39
70
  must_belong_to :faz
40
- must_have_one :boo
71
+ must_have_one :zer
41
72
  must_have_many :bams
42
73
  must_have_many_through :bars, :bams
43
74
  must_have_and_belong_to_many :berks
44
75
 
76
+ This functionality is separately available by adding:
45
77
 
46
- ### Validation Matchers
78
+ require 'minitest_rails_tools/association_matchers'
47
79
 
48
- You may use this to test a couple of Rails' validations in your tests:
49
80
 
50
- subject { FactoryGirl.create :foo }
51
-
52
- must_validate_presence_of :bar
53
- must_validate_uniqueness_of :baz
81
+ ### Expectations
82
+
83
+ This adds a couple of extra expectations to improve readability:
84
+
85
+ Bar.must_differ('count', -1) do
86
+ delete :destroy, :id => subject.to_param
87
+ end
88
+
89
+ subject.foos.must_have_size 20
90
+
91
+ subject.foos.must_have_same_elements_as Foo.all
92
+
93
+ This functionality is separately available by adding:
94
+
95
+ require 'minitest_rails_tools/expectations'
54
96
 
55
97
 
56
98
  ### Helper Extension
57
99
 
58
- This allows you to define a helper as your subject (and then call your helper methods on it):
100
+ This allows you to define a helper as your subject (and then call your helper
101
+ methods on it):
59
102
 
60
103
  subject { helper :foo_helper }
61
-
104
+
62
105
  subject.do_my_stuff.must_equal 'OK'
63
106
 
107
+ This functionality is separately available by adding:
108
+
109
+ require 'minitest_rails_tools/helper_extension'
110
+
111
+
112
+ ### Validation Matchers
113
+
114
+ You may use this to test a couple of Rails' validations in your tests:
115
+
116
+ subject { FactoryGirl.create :foo }
117
+
118
+ must_validate_presence_of :bar
119
+ must_validate_uniqueness_of :baz
120
+ must_validate_length_of :zer, :minimum => 2, :maximum => 5
121
+
122
+ This functionality is separately available by adding:
123
+
124
+ require 'minitest_rails_tools/validation_matchers'
64
125
 
65
126
 
66
- Copyright © 2013 SUSE released under the MIT license. For full details see LICENSE included in this distribution.
127
+ Copyright © 2013 SUSE released under the MIT license.
128
+ For full details see LICENSE included in this distribution.
@@ -1,4 +1,5 @@
1
- require 'association_matchers'
2
- require 'validation_matchers'
3
- require 'helper_extension'
4
- require 'application_integration'
1
+ require_relative 'minitest_rails_tools/application_integration'
2
+ require_relative 'minitest_rails_tools/association_matchers'
3
+ require_relative 'minitest_rails_tools/expectations'
4
+ require_relative 'minitest_rails_tools/helper_extension'
5
+ require_relative 'minitest_rails_tools/validation_matchers'
@@ -1,3 +1,5 @@
1
+ require 'minitest/autorun'
2
+
1
3
  class MiniTest::Spec
2
4
  include Rails.application.routes.url_helpers
3
5
  end
@@ -1,3 +1,5 @@
1
+ require 'minitest/autorun'
2
+
1
3
  # Allows for some automagic association tests.
2
4
 
3
5
  def must_belong_to(association_name)
@@ -0,0 +1,49 @@
1
+ require 'minitest/autorun'
2
+
3
+ module MiniTest::Assertions
4
+
5
+ def assert_count(value, list)
6
+ size = list.size
7
+ assert_equal value, size, "Expected size to be #{value}, but was #{size}"
8
+ end
9
+
10
+ def assert_same_elements(value, list)
11
+ assert_equal(
12
+ list.sort, value.sort,
13
+ "Expected #{list} to have the same elements as #{value}"
14
+ )
15
+ end
16
+
17
+ def assert_difference(expression, difference = 1, message = nil, &block)
18
+ expressions = Array.wrap expression
19
+ exps = expressions.collect do |e|
20
+ e.respond_to?(:call) ? e : lambda { eval(e, block.binding) }
21
+ end
22
+ before = exps.collect(&:call)
23
+
24
+ yield
25
+
26
+ expressions.zip(exps).each_with_index do |(code, e), i|
27
+ error = "#{code.inspect} didn't change by #{difference}"
28
+ error = "#{message}.\n#{error}" if message
29
+ assert_equal(before[i] + difference, e.call, error)
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ class Object
36
+
37
+ include MiniTest::Assertions
38
+
39
+ def must_differ(expression, difference = 1, message = nil, &block)
40
+ metaclass = class << self; self end
41
+ metaclass.send(:define_method, :callback)
42
+ assert_difference("#{self}.#{expression}", difference, message, &block)
43
+ end
44
+
45
+ end
46
+
47
+ Object.infect_an_assertion :assert_count, :must_count
48
+ Object.infect_an_assertion :assert_count, :must_have_size
49
+ Array.infect_an_assertion :assert_same_elements, :must_have_same_elements_as
@@ -1,3 +1,5 @@
1
+ require 'minitest/autorun'
2
+
1
3
  class HelperExtension
2
4
 
3
5
  include ActionView::Helpers
@@ -1,3 +1,5 @@
1
+ require 'minitest/autorun'
2
+
1
3
  # Allows for some automagic association tests.
2
4
  # Expects 'subject' to be defined. E.g.
3
5
  # subject { FactoryGirl.create :foo }
metadata CHANGED
@@ -1,18 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest_rails_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Dominik Bamberger
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-21 00:00:00.000000000 Z
13
- dependencies: []
14
- description: A collection of little helpers to make working with Rails and Minitest
15
- a bit easier.
11
+ date: 2013-05-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A collection of helpers for integrating Rails and Minitest.
16
42
  email: bamboo@suse.com
17
43
  executables: []
18
44
  extensions: []
@@ -21,32 +47,33 @@ files:
21
47
  - LICENSE
22
48
  - README.md
23
49
  - lib/minitest_rails_tools.rb
24
- - lib/application_integration.rb
25
- - lib/helper_extension.rb
26
- - lib/association_matchers.rb
27
- - lib/validation_matchers.rb
50
+ - lib/minitest_rails_tools/application_integration.rb
51
+ - lib/minitest_rails_tools/helper_extension.rb
52
+ - lib/minitest_rails_tools/association_matchers.rb
53
+ - lib/minitest_rails_tools/expectations.rb
54
+ - lib/minitest_rails_tools/validation_matchers.rb
28
55
  homepage: http://github.com/openSUSE/minitest_rails_tools
29
- licenses: []
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
30
59
  post_install_message:
31
60
  rdoc_options: []
32
61
  require_paths:
33
62
  - lib
34
63
  required_ruby_version: !ruby/object:Gem::Requirement
35
- none: false
36
64
  requirements:
37
- - - ! '>='
65
+ - - '>='
38
66
  - !ruby/object:Gem::Version
39
67
  version: '0'
40
68
  required_rubygems_version: !ruby/object:Gem::Requirement
41
- none: false
42
69
  requirements:
43
- - - ! '>='
70
+ - - '>='
44
71
  - !ruby/object:Gem::Version
45
72
  version: '0'
46
73
  requirements: []
47
74
  rubyforge_project:
48
- rubygems_version: 1.8.23
75
+ rubygems_version: 2.0.0
49
76
  signing_key:
50
- specification_version: 3
77
+ specification_version: 4
51
78
  summary: Smoothen Minitest/Rails integration
52
79
  test_files: []