minitest-rails-shoulda 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
+ log/*
4
5
  pkg/*
@@ -0,0 +1 @@
1
+ 1.9.3@minitest-rails-shoulda
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source :rubygems
2
2
 
3
3
  # Specify your gem's dependencies in minitest-rails-shoulda.gemspec
4
4
  gemspec
@@ -10,6 +10,10 @@ In Rails 3 and Bundler, add the following to your Gemfile:
10
10
  gem "minitest-rails-shoulda"
11
11
  end
12
12
 
13
+ Add the following to your test helper:
14
+
15
+ require "minitest/rails/shoulda"
16
+
13
17
  == Usage
14
18
 
15
19
  === ActiveRecord Matchers
@@ -64,3 +68,7 @@ Matchers to test common patterns:
64
68
  end
65
69
  end
66
70
 
71
+ === Contributors
72
+
73
+ * Phil Cohen <github@phlippers.net>
74
+ * Mike Moore <mike@blowmage.com>
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require "rake/testtask"
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "lib" << "test"
6
+ t.pattern = "test/**/test_*.rb"
7
+ t.verbose = true
8
+ end
@@ -1,12 +1,9 @@
1
- require "minitest-rails-shoulda/version"
2
- require "minitest/rails"
3
- require "minitest/matchers"
4
- require "minitest-rails-shoulda/integrations"
1
+ require "minitest-rails"
2
+ require "minitest/rails/shoulda"
5
3
 
6
- module MiniTest
4
+ module Minitest
7
5
  module Rails
8
6
  module Shoulda
9
- # Your code goes here...
10
7
  end
11
8
  end
12
9
  end
@@ -0,0 +1,4 @@
1
+ require "minitest/rails/shoulda/version"
2
+ require "minitest/rails/shoulda/assertions"
3
+ require "minitest/rails/shoulda/dsl"
4
+ require "minitest/rails/shoulda/matchers"
@@ -0,0 +1,110 @@
1
+ require "minitest/unit"
2
+
3
+ # Add Shoulda's assertions to MiniTest
4
+
5
+ module MiniTest
6
+ module Assertions
7
+
8
+ # Asserts that two arrays contain the same elements, the same number of times. Essentially ==, but unordered.
9
+ #
10
+ # assert_same_elements([:a, :b, :c], [:c, :a, :b]) => passes
11
+ def assert_same_elements(a1, a2, msg = nil)
12
+ [:select, :inject, :size].each do |m|
13
+ [a1, a2].each {|a| assert_respond_to(a, m, "Are you sure that #{a.inspect} is an array? It doesn't respond to #{m}.") }
14
+ end
15
+
16
+ assert a1h = a1.inject({}) { |h,e| h[e] ||= a1.select { |i| i == e }.size; h }
17
+ assert a2h = a2.inject({}) { |h,e| h[e] ||= a2.select { |i| i == e }.size; h }
18
+
19
+ assert_equal(a1h, a2h, msg)
20
+ end
21
+
22
+ # Fails if two arrays contain the same elements. Essentially ==, but unordered.
23
+ #
24
+ # refute_same_elements([:a, :b, :c], [:c, :a, :d]) => passes
25
+ def refute_same_elements(a1, a2, msg = nil)
26
+ [:select, :inject, :size].each do |m|
27
+ [a1, a2].each {|a| assert_respond_to(a, m, "Are you sure that #{a.inspect} is an array? It doesn't respond to #{m}.") }
28
+ end
29
+
30
+ assert a1h = a1.inject({}) { |h,e| h[e] ||= a1.select { |i| i == e }.size; h }
31
+ assert a2h = a2.inject({}) { |h,e| h[e] ||= a2.select { |i| i == e }.size; h }
32
+
33
+ refute_equal(a1h, a2h, msg)
34
+ end
35
+
36
+ # Asserts that the given collection contains item x.
37
+ # If x is a regular expression, ensure that
38
+ # at least one element from the collection matches x.
39
+ # +extra_msg+ is appended to the error message if the assertion fails.
40
+ #
41
+ # assert_contains(['a', '1'], /\d/) => passes
42
+ # assert_contains(['a', '1'], 'a') => passes
43
+ # assert_contains(['a', '1'], /not there/) => fails
44
+ def assert_contains(collection, x, extra_msg = "")
45
+ collection = Array(collection)
46
+ msg = "#{x.inspect} not found in #{collection.to_a.inspect} #{extra_msg}"
47
+ case x
48
+ when Regexp
49
+ assert(collection.detect { |e| e =~ x }, msg)
50
+ else
51
+ assert(collection.include?(x), msg)
52
+ end
53
+ end
54
+
55
+ # Asserts that the given collection does not contain item x.
56
+ # If x is a regular expression, ensure that
57
+ # none of the elements from the collection match x.
58
+ def assert_does_not_contain(collection, x, extra_msg = "")
59
+ collection = Array(collection)
60
+ msg = "#{x.inspect} found in #{collection.to_a.inspect} " + extra_msg
61
+ case x
62
+ when Regexp
63
+ assert(!collection.detect { |e| e =~ x }, msg)
64
+ else
65
+ assert(!collection.include?(x), msg)
66
+ end
67
+ end
68
+
69
+ # Asserts that the given matcher returns true when +target+ is passed to #matches?
70
+ def assert_accepts(matcher, target, options = {})
71
+ if matcher.respond_to?(:in_context)
72
+ matcher.in_context(self)
73
+ end
74
+
75
+ if matcher.matches?(target)
76
+ pass
77
+ if options[:message]
78
+ assert_match options[:message], matcher.negative_failure_message
79
+ end
80
+ else
81
+ flunk matcher.failure_message
82
+ end
83
+ end
84
+
85
+ # Asserts that the given matcher returns true when +target+ is passed to #does_not_match?
86
+ # or false when +target+ is passed to #matches? if #does_not_match? is not implemented
87
+ def assert_rejects(matcher, target, options = {})
88
+ if matcher.respond_to?(:in_context)
89
+ matcher.in_context(self)
90
+ end
91
+
92
+ not_match = matcher.respond_to?(:does_not_match?) ? matcher.does_not_match?(target) : !matcher.matches?(target)
93
+
94
+ if not_match
95
+ pass
96
+ if options[:message]
97
+ assert_match options[:message], matcher.failure_message
98
+ end
99
+ else
100
+ flunk matcher.negative_failure_message
101
+ end
102
+ end
103
+
104
+ alias :refute_contains :assert_does_not_contain
105
+ alias :refute_does_not_contain :assert_contains
106
+
107
+ alias :refute_accepts :assert_rejects
108
+ alias :refute_rejects :assert_accepts
109
+ end
110
+ end
@@ -0,0 +1,28 @@
1
+ require "minitest/spec"
2
+
3
+ # Duck punch MiniTest::Spec to behave more like Shoulda
4
+
5
+ class MiniTest::Spec < MiniTest::Unit::TestCase
6
+ class << self
7
+
8
+ # Add Shoulda DSL
9
+ alias :setup :before
10
+ alias :teardown :after
11
+ alias :context :describe
12
+ alias :should :it
13
+
14
+ ##
15
+ # Define a named expectation to be skipped for now.
16
+ # The implementation may or may not be present.
17
+ # The test is listed but does not cause a failure.
18
+ #
19
+ # Add here so we have something to alias later...
20
+ def skip desc = "skipped", &block
21
+ it desc do
22
+ skip desc
23
+ end
24
+ end unless respond_to?(:skip)
25
+
26
+ alias :should_eventually :skip
27
+ end
28
+ end
@@ -0,0 +1,69 @@
1
+ require "minitest/matchers"
2
+
3
+ if defined?(ActiveRecord)
4
+ require "minitest/rails/active_support"
5
+ require "shoulda/matchers/active_record"
6
+
7
+ Shoulda::Matchers::ActiveRecord.module_eval do
8
+ def self.included(base)
9
+ instance_methods.each do |name|
10
+ base.register_matcher name, name
11
+ end
12
+ end
13
+ end
14
+
15
+ class MiniTest::Rails::ActiveSupport::TestCase
16
+ include Shoulda::Matchers::ActiveRecord
17
+ end
18
+ end
19
+
20
+ if defined?(ActiveModel)
21
+ require "minitest/rails/active_support"
22
+ require "shoulda/matchers/active_model"
23
+
24
+ Shoulda::Matchers::ActiveModel.module_eval do
25
+ def self.included(base)
26
+ instance_methods.each do |name|
27
+ base.register_matcher name, name
28
+ end
29
+ end
30
+ end
31
+
32
+ class MiniTest::Rails::ActiveSupport::TestCase
33
+ include Shoulda::Matchers::ActiveModel
34
+ end
35
+ end
36
+
37
+ if defined?(ActionController)
38
+ require "minitest/rails/action_controller"
39
+ require "shoulda/matchers/action_controller"
40
+
41
+ Shoulda::Matchers::ActionController.module_eval do
42
+ def self.included(base)
43
+ instance_methods.each do |name|
44
+ base.register_matcher name, name
45
+ end
46
+ end
47
+ end
48
+
49
+ class MiniTest::Rails::ActionController::TestCase
50
+ include Shoulda::Matchers::ActionController
51
+ end
52
+ end
53
+
54
+ if defined?(ActionMailer)
55
+ require "minitest/rails/action_mailer"
56
+ require "shoulda/matchers/action_mailer"
57
+
58
+ Shoulda::Matchers::ActionMailer.module_eval do
59
+ def self.included(base)
60
+ instance_methods.each do |name|
61
+ base.register_matcher name, name
62
+ end
63
+ end
64
+ end
65
+
66
+ class MiniTest::Rails::ActionMailer::TestCase
67
+ include Shoulda::Matchers::ActionMailer
68
+ end
69
+ end
@@ -1,7 +1,7 @@
1
1
  module MiniTest
2
2
  module Rails
3
3
  module Shoulda
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
@@ -1,6 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "minitest-rails-shoulda/version"
2
+ require File.expand_path("../lib/minitest/rails/shoulda/version", __FILE__)
4
3
 
5
4
  Gem::Specification.new do |s|
6
5
  s.name = "minitest-rails-shoulda"
@@ -20,5 +19,5 @@ Gem::Specification.new do |s|
20
19
 
21
20
  s.add_runtime_dependency "minitest-rails", "~> 0.2.0"
22
21
  s.add_runtime_dependency "minitest-matchers", "~> 1.2.0"
23
- s.add_runtime_dependency "shoulda-matchers", "~> 1.3.0"
22
+ s.add_runtime_dependency "shoulda-matchers", "~> 1.4.1"
24
23
  end
@@ -0,0 +1,31 @@
1
+ require "minitest/autorun"
2
+ require "action_controller/railtie"
3
+
4
+ class TestApp < Rails::Application
5
+ config.secret_token = "821c600ece97fc4ba952d67655b4b475"
6
+ initialize!
7
+ routes.draw do
8
+ root to: 'hello#world'
9
+ end
10
+ end
11
+ class HelloController < ActionController::Base
12
+ def world
13
+ render inline: "<!DOCTYPE html><title>TestApp</title>
14
+ <h1>Hello <span>World</span></h1>
15
+ <nav><ul><li><a href='/'>home</a></li></ul></nav>
16
+ <p><label>Email Address<input type='text'></label></p>
17
+ <button>random button</button>
18
+ <label>going<input type='checkbox' checked='checked'></label>
19
+ <label>avoid<input type='checkbox'></label>"
20
+ end
21
+ end
22
+
23
+ Rails.application = TestApp
24
+
25
+ require "minitest/rails"
26
+ require "minitest/rails/shoulda"
27
+
28
+ begin
29
+ require 'turn/autorun'
30
+ Turn.config.format = :progress
31
+ rescue LoadError; end
@@ -0,0 +1,47 @@
1
+ require "minitest/autorun"
2
+ require "minitest/rails/shoulda/dsl"
3
+ require "minitest/rails/shoulda/assertions"
4
+
5
+ describe "Shoulda Style Assertions" do
6
+
7
+ context "an array of values" do
8
+
9
+ setup do
10
+ @a = ['abc', 'def', 3]
11
+ end
12
+
13
+ [/b/, 'abc', 3].each do |x|
14
+ should "contain #{x.inspect}" do
15
+ assert_raises(MiniTest::Assertion) do
16
+ assert_does_not_contain @a, x
17
+ end
18
+ assert_contains @a, x
19
+ refute_does_not_contain @a, x
20
+ end
21
+ end
22
+
23
+ should "not contain 'wtf'" do
24
+ assert_raises(MiniTest::Assertion) {assert_contains @a, 'wtf'}
25
+ assert_does_not_contain @a, 'wtf'
26
+ refute_contains @a, 'wtf'
27
+ end
28
+
29
+ should "be the same as another array, ordered differently" do
30
+ assert_same_elements(@a, [3, "def", "abc"])
31
+
32
+ assert_raises(MiniTest::Assertion) do
33
+ assert_same_elements(@a, [3, 3, "def", "abc"])
34
+ end
35
+ refute_same_elements(@a, [3, 3, "def", "abc"])
36
+
37
+ assert_same_elements([@a, "abc"].flatten, ["abc", 3, "def", "abc"])
38
+
39
+ assert_raises(MiniTest::Assertion) do
40
+ assert_same_elements([@a, "abc"].flatten, [3, 3, "def", "abc"])
41
+ end
42
+ refute_same_elements([@a, "abc"].flatten, [3, 3, "def", "abc"])
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,187 @@
1
+ require "rails_helper"
2
+
3
+ describe HelloController do
4
+
5
+ context "index" do
6
+ setup do
7
+ get :world
8
+ end
9
+
10
+ describe "assertions" do
11
+ it "should give us HTML" do
12
+ assert_respond_with_content_type(@controller, :html)
13
+ end
14
+
15
+ it "should not give us XML" do
16
+ refute_respond_with_content_type(@controller, :xml)
17
+ end
18
+ end
19
+
20
+ describe "with matchers" do
21
+ should "give us HTML" do
22
+ @controller.must respond_with_content_type(:html)
23
+ end
24
+
25
+ should_eventually "give us JSON"
26
+
27
+ # should_eventually "give us JSON" do
28
+ # @controller.must respond_with_content_type(:json)
29
+ # end
30
+
31
+ should "not give us XML" do
32
+ @controller.wont respond_with_content_type(:xml)
33
+ end
34
+ end
35
+
36
+ describe "with subject" do
37
+ subject { @controller }
38
+
39
+ it { must respond_with_content_type(:html) }
40
+ it { wont respond_with_content_type(:xml) }
41
+
42
+ must { respond_with_content_type(:html) }
43
+ wont { respond_with_content_type(:xml) }
44
+ end
45
+ end
46
+
47
+ # describe "have_content" do
48
+ # it "has page with content" do
49
+ # visit root_path
50
+ # assert_have_content page, "Hello World"
51
+ # refute_have_content page, "Goobye All!"
52
+ # page.must_have_content "Hello World"
53
+ # page.wont_have_content "Goobye All!"
54
+ # end
55
+
56
+ # describe "with subject" do
57
+ # before { visit(root_path) }
58
+ # subject { page }
59
+
60
+ # it { must have_content("Hello World") }
61
+ # it { wont have_content("Goobye All!") }
62
+ # must { have_content("Hello World") }
63
+ # wont { have_content("Goobye All!") }
64
+ # end
65
+ # end
66
+
67
+ # describe "have_selector" do
68
+ # it "has page with heading" do
69
+ # visit root_path
70
+ # assert_have_selector page, "h1"
71
+ # refute_have_selector page, "h3"
72
+ # page.must_have_selector "h1"
73
+ # page.wont_have_selector "h3"
74
+ # end
75
+
76
+ # describe "with subject" do
77
+ # before { visit(root_path) }
78
+ # subject { page }
79
+
80
+ # it { must have_selector("h1") }
81
+ # it { wont have_selector("h3") }
82
+ # must { have_selector("h1") }
83
+ # wont { have_selector("h3") }
84
+ # end
85
+ # end
86
+
87
+ # describe "have_link" do
88
+ # it "has a link to home" do
89
+ # visit root_path
90
+ # assert_have_link page, "home"
91
+ # refute_have_link page, "away"
92
+ # page.must_have_link "home"
93
+ # page.wont_have_link "away"
94
+ # end
95
+
96
+ # describe "with subject" do
97
+ # before { visit(root_path) }
98
+ # subject { page }
99
+
100
+ # it { must have_link("home") }
101
+ # it { wont have_link("away") }
102
+ # must { have_link("home") }
103
+ # wont { have_link("away") }
104
+ # end
105
+ # end
106
+
107
+ # describe "have_field" do
108
+ # it "has a button to submit" do
109
+ # visit root_path
110
+ # assert_have_field page, "Email Address"
111
+ # refute_have_field page, "Bank Account"
112
+ # page.must_have_field "Email Address"
113
+ # page.wont_have_field "Bank Account"
114
+ # end
115
+
116
+ # describe "with subject" do
117
+ # before { visit(root_path) }
118
+ # subject { page }
119
+
120
+ # it { must have_field("Email Address") }
121
+ # it { wont have_field("Bank Account") }
122
+ # must { have_field("Email Address") }
123
+ # wont { have_field("Bank Account") }
124
+ # end
125
+ # end
126
+
127
+ # describe "have_button" do
128
+ # it "has a button to login" do
129
+ # visit root_path
130
+ # assert_have_button page, "random button"
131
+ # refute_have_button page, "missing button"
132
+ # page.must_have_button "random button"
133
+ # page.wont_have_button "missing button"
134
+ # end
135
+
136
+ # describe "with subject" do
137
+ # before { visit(root_path) }
138
+ # subject { page }
139
+
140
+ # it { must have_button("random button") }
141
+ # it { wont have_button("missing button") }
142
+ # must { have_button("random button") }
143
+ # wont { have_button("missing button") }
144
+ # end
145
+ # end
146
+
147
+ # describe "have_checked_field" do
148
+ # it "has a button to submit" do
149
+ # visit root_path
150
+ # assert_have_checked_field page, "going"
151
+ # refute_have_checked_field page, "avoid"
152
+ # page.must_have_checked_field "going"
153
+ # page.wont_have_checked_field "avoid"
154
+ # end
155
+
156
+ # describe "with subject" do
157
+ # before { visit(root_path) }
158
+ # subject { page }
159
+
160
+ # it { must have_checked_field("going") }
161
+ # it { wont have_checked_field("avoid") }
162
+ # must { have_checked_field("going") }
163
+ # wont { have_checked_field("avoid") }
164
+ # end
165
+ # end
166
+
167
+ # describe "have_unchecked_field" do
168
+ # it "has a button to submit" do
169
+ # visit root_path
170
+ # assert_have_unchecked_field page, "avoid"
171
+ # refute_have_unchecked_field page, "going"
172
+ # page.must_have_unchecked_field "avoid"
173
+ # page.wont_have_unchecked_field "going"
174
+ # end
175
+
176
+ # describe "with subject" do
177
+ # before { visit(root_path) }
178
+ # subject { page }
179
+
180
+ # it { must have_unchecked_field("avoid") }
181
+ # it { wont have_unchecked_field("going") }
182
+ # must { have_unchecked_field("avoid") }
183
+ # wont { have_unchecked_field("going") }
184
+ # end
185
+ # end
186
+
187
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-rails-shoulda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-27 00:00:00.000000000 Z
13
+ date: 2012-10-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: minitest-rails
@@ -51,7 +51,7 @@ dependencies:
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 1.3.0
54
+ version: 1.4.1
55
55
  type: :runtime
56
56
  prerelease: false
57
57
  version_requirements: !ruby/object:Gem::Requirement
@@ -59,7 +59,7 @@ dependencies:
59
59
  requirements:
60
60
  - - ~>
61
61
  - !ruby/object:Gem::Version
62
- version: 1.3.0
62
+ version: 1.4.1
63
63
  description: Making shoulda-matchers available for minitest-rails
64
64
  email:
65
65
  - robert@robertbousquet.com
@@ -69,15 +69,22 @@ extensions: []
69
69
  extra_rdoc_files: []
70
70
  files:
71
71
  - .gitignore
72
+ - .ruby-version
72
73
  - CHANGELOG.txt
73
74
  - Gemfile
74
75
  - License.txt
75
76
  - README.rdoc
76
77
  - Rakefile
77
78
  - lib/minitest-rails-shoulda.rb
78
- - lib/minitest-rails-shoulda/integrations.rb
79
- - lib/minitest-rails-shoulda/version.rb
79
+ - lib/minitest/rails/shoulda.rb
80
+ - lib/minitest/rails/shoulda/assertions.rb
81
+ - lib/minitest/rails/shoulda/dsl.rb
82
+ - lib/minitest/rails/shoulda/matchers.rb
83
+ - lib/minitest/rails/shoulda/version.rb
80
84
  - minitest-rails-shoulda.gemspec
85
+ - test/rails_helper.rb
86
+ - test/test_assertions.rb
87
+ - test/test_matchers.rb
81
88
  homepage: ''
82
89
  licenses: []
83
90
  post_install_message:
@@ -90,16 +97,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
97
  - - ! '>='
91
98
  - !ruby/object:Gem::Version
92
99
  version: '0'
100
+ segments:
101
+ - 0
102
+ hash: -2081821548100069152
93
103
  required_rubygems_version: !ruby/object:Gem::Requirement
94
104
  none: false
95
105
  requirements:
96
106
  - - ! '>='
97
107
  - !ruby/object:Gem::Version
98
108
  version: '0'
109
+ segments:
110
+ - 0
111
+ hash: -2081821548100069152
99
112
  requirements: []
100
113
  rubyforge_project: minitest-rails-shoulda
101
114
  rubygems_version: 1.8.24
102
115
  signing_key:
103
116
  specification_version: 3
104
117
  summary: Making shoulda-matchers available for minitest-rails
105
- test_files: []
118
+ test_files:
119
+ - test/rails_helper.rb
120
+ - test/test_assertions.rb
121
+ - test/test_matchers.rb
@@ -1,36 +0,0 @@
1
- if defined? ActionController
2
- require "shoulda/matchers/action_controller"
3
-
4
- class MiniTest::Rails::ActionController::TestCase
5
- include Shoulda::Matchers::ActionController
6
- extend Shoulda::Matchers::ActionController
7
- end
8
- end
9
-
10
- if defined? ActionMailer
11
- require "shoulda/matchers/action_mailer"
12
-
13
- class MiniTest::Rails::ActionMailer::TestCase
14
- include Shoulda::Matchers::ActionMailer
15
- extend Shoulda::Matchers::ActionMailer
16
- end
17
- end
18
-
19
- if defined? ActiveRecord
20
- require "shoulda/matchers/active_record"
21
- require "shoulda/matchers/active_model"
22
-
23
- class MiniTest::Rails::ActiveSupport::TestCase
24
- include Shoulda::Matchers::ActiveRecord
25
- extend Shoulda::Matchers::ActiveRecord
26
- include Shoulda::Matchers::ActiveModel
27
- extend Shoulda::Matchers::ActiveModel
28
- end
29
- elsif defined? ActiveModel
30
- require "shoulda/matchers/active_model"
31
-
32
- class MiniTest::Rails::ActiveSupport::TestCase
33
- include Shoulda::Matchers::ActiveModel
34
- extend Shoulda::Matchers::ActiveModel
35
- end
36
- end