assert_difference 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -8
- data/Gemfile +7 -0
- data/LICENSE +1 -1
- data/README.md +54 -0
- data/Rakefile +16 -66
- data/assert_difference.gemspec +24 -0
- data/lib/assert_difference.rb +33 -25
- metadata +41 -65
- data/.document +0 -5
- data/README.rdoc +0 -34
- data/VERSION +0 -1
data/.gitignore
CHANGED
@@ -16,15 +16,14 @@ tmtags
|
|
16
16
|
## RubyMine
|
17
17
|
.idea
|
18
18
|
|
19
|
-
## PROJECT::GENERAL
|
20
|
-
coverage
|
21
|
-
rdoc
|
22
|
-
pkg
|
23
|
-
|
24
|
-
## PROJECT::SPECIFIC
|
25
|
-
*.gemspec
|
26
|
-
|
27
19
|
## Yard
|
28
20
|
.yardoc
|
29
21
|
doc
|
30
22
|
|
23
|
+
## PROJECT::GENERAL
|
24
|
+
coverage
|
25
|
+
rdoc
|
26
|
+
pkg
|
27
|
+
.bundle
|
28
|
+
tmp
|
29
|
+
Gemfile.lock
|
data/Gemfile
ADDED
data/LICENSE
CHANGED
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
assert_difference
|
2
|
+
=================
|
3
|
+
|
4
|
+
A nice assert_difference method similar to the one provided by Rails but with
|
5
|
+
some improvements. For example:
|
6
|
+
|
7
|
+
assert_difference "Company.count" => +1, "User.count" => +5, "Slot.count" => -1 do
|
8
|
+
post :something
|
9
|
+
end
|
10
|
+
|
11
|
+
will assert that a company and 5 users were create (the plus sign is only for
|
12
|
+
the visual aid) and a slot was removed.
|
13
|
+
|
14
|
+
[Rails' assert_difference](http://api.rubyonrails.org/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_difference)
|
15
|
+
would require a more verbose syntax:
|
16
|
+
|
17
|
+
assert_difference "Company.count" do
|
18
|
+
assert_difference "User.count", +5 do
|
19
|
+
assert_difference "Article.count", -1 do
|
20
|
+
post :something
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
To use it with Test::Unit add this code (untested, please
|
26
|
+
[let me know](mailto:pupeno@pupeno.com) if it works):
|
27
|
+
|
28
|
+
class Test::Unit::TestCase
|
29
|
+
include Factory::Syntax::Methods
|
30
|
+
end
|
31
|
+
|
32
|
+
and to use it with RSpec:
|
33
|
+
|
34
|
+
RSpec.configure do |config|
|
35
|
+
config.include Factory::Syntax::Methods
|
36
|
+
end
|
37
|
+
|
38
|
+
For more information read http://pupeno.com/blog/better-assert-difference
|
39
|
+
|
40
|
+
Note on Patches/Pull Requests
|
41
|
+
-----------------------------
|
42
|
+
|
43
|
+
* Fork the project.
|
44
|
+
* Make your feature addition or bug fix.
|
45
|
+
* Add tests for it. This is important so I don't break it in a
|
46
|
+
future version unintentionally.
|
47
|
+
* Commit, do not mess with rakefile, version, or history.
|
48
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
49
|
+
* Send me a pull request. Bonus points for topic branches.
|
50
|
+
|
51
|
+
Copyright
|
52
|
+
---------
|
53
|
+
|
54
|
+
Copyright (c) 2010, 2011, José Pablo Fernández. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,24 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# Copyright © 2011, José Pablo Fernández
|
2
3
|
|
3
|
-
|
4
|
-
require "rake"
|
4
|
+
task :default => :test
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
Jeweler::Tasks.new do |gem|
|
9
|
-
gem.name = "assert_difference"
|
10
|
-
gem.summary = %Q{Better assert_difference than Rails}
|
11
|
-
gem.description = %Q{Better assert_difference than Rails by providing a more compact and readable syntax through hashes. For some more information read http://pupeno.com/blog/better-assert-difference}
|
12
|
-
gem.email = "pupeno@pupeno.com"
|
13
|
-
gem.homepage = "http://github.com/pupeno/assert_difference"
|
14
|
-
gem.authors = ["J. Pablo Fernández"]
|
15
|
-
gem.add_development_dependency "yard", ">= 0"
|
16
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
-
end
|
18
|
-
Jeweler::GemcutterTasks.new
|
19
|
-
rescue LoadError
|
20
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
-
end
|
6
|
+
require "bundler"
|
7
|
+
Bundler::GemHelper.install_tasks
|
22
8
|
|
23
9
|
require "rake/testtask"
|
24
10
|
Rake::TestTask.new(:test) do |test|
|
@@ -27,53 +13,17 @@ Rake::TestTask.new(:test) do |test|
|
|
27
13
|
test.verbose = true
|
28
14
|
end
|
29
15
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
test.verbose = true
|
36
|
-
end
|
37
|
-
rescue LoadError
|
38
|
-
task :rcov do
|
39
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
task :test => :check_dependencies
|
44
|
-
|
45
|
-
begin
|
46
|
-
require "reek/adapters/rake_task"
|
47
|
-
Reek::RakeTask.new do |t|
|
48
|
-
t.fail_on_error = true
|
49
|
-
t.verbose = false
|
50
|
-
t.source_files = "lib/**/*.rb"
|
51
|
-
end
|
52
|
-
rescue LoadError
|
53
|
-
task :reek do
|
54
|
-
abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
begin
|
59
|
-
require "roodi"
|
60
|
-
require "roodi_task"
|
61
|
-
RoodiTask.new do |t|
|
62
|
-
t.verbose = false
|
63
|
-
end
|
64
|
-
rescue LoadError
|
65
|
-
task :roodi do
|
66
|
-
abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
|
67
|
-
end
|
16
|
+
require "rcov/rcovtask"
|
17
|
+
Rcov::RcovTask.new do |test|
|
18
|
+
test.libs << "test"
|
19
|
+
test.pattern = "test/**/test_*.rb"
|
20
|
+
test.verbose = true
|
68
21
|
end
|
69
22
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
task :yardoc do
|
77
|
-
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
78
|
-
end
|
23
|
+
require "yard"
|
24
|
+
YARD::Rake::YardocTask.new do |yard|
|
25
|
+
# Use Markdown for documentation.
|
26
|
+
yard.options << "--markup" << "markdown"
|
27
|
+
# Extra file(s).
|
28
|
+
yard.options << "-" << "LICENSE"
|
79
29
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# Copyright © 2011, José Pablo Fernández
|
3
|
+
|
4
|
+
$:.unshift File.expand_path("../lib", __FILE__)
|
5
|
+
require "assert_difference"
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "assert_difference"
|
9
|
+
s.version = AssertDifference::VERSION
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.authors = ["J. Pablo Fernández"]
|
12
|
+
s.email = ["pupeno@pupeno.com"]
|
13
|
+
s.homepage = "http://github.com/pupeno/assert_difference"
|
14
|
+
s.summary = "An improved assert_difference"
|
15
|
+
s.description = "Better assert_difference than Rails by providing a more compact and readable syntax through hashes. For some more information read http://pupeno.com/blog/better-assert-difference."
|
16
|
+
|
17
|
+
s.required_rubygems_version = ">= 1.3.6"
|
18
|
+
s.rubyforge_project = "assert_difference"
|
19
|
+
|
20
|
+
s.add_development_dependency "yard"
|
21
|
+
|
22
|
+
s.files = `git ls-files`.split("\n")
|
23
|
+
s.test_files = `git ls-files -- {test}/*`.split("\n")
|
24
|
+
end
|
data/lib/assert_difference.rb
CHANGED
@@ -1,52 +1,60 @@
|
|
1
|
-
#
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# Copyright © 2010, 2011, José Pablo Fernández
|
3
|
+
|
4
|
+
module AssertDifference
|
5
|
+
VERSION = "0.3.0" unless defined?(::AssertDifference::VERSION)
|
2
6
|
|
3
|
-
class ActiveSupport::TestCase
|
4
7
|
# Test numeric difference between the return value of an expression as a result of what is evaluated
|
5
8
|
# in the yielded block.
|
6
9
|
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
+
# assert_difference "Article.count" do
|
11
|
+
# post :create, :article => {...}
|
12
|
+
# end
|
10
13
|
#
|
11
14
|
# An arbitrary expression is passed in and evaluated.
|
12
15
|
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
+
# assert_difference "assigns(:article).comments(:reload).size" do
|
17
|
+
# post :create, :comment => {...}
|
18
|
+
# end
|
16
19
|
#
|
17
20
|
# An arbitrary positive or negative difference can be specified. The default is +1.
|
18
21
|
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
+
# assert_difference "Article.count", -1 do
|
23
|
+
# post :delete, :id => ...
|
24
|
+
# end
|
22
25
|
#
|
23
26
|
# An array of expressions can also be passed in and evaluated.
|
24
27
|
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
+
# assert_difference [ "Article.count", "Post.count" ], +2 do
|
29
|
+
# post :create, :article => {...}
|
30
|
+
# end
|
28
31
|
#
|
29
32
|
# A error message can be specified.
|
30
33
|
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
+
# assert_difference "Article.count", -1, "An Article should be destroyed" do
|
35
|
+
# post :delete, :id => ...
|
36
|
+
# end
|
34
37
|
#
|
35
38
|
# Various assertions can be combined into one, instead of writing:
|
36
39
|
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
40
|
+
# assert_difference "Company.count" do
|
41
|
+
# assert_difference "User.count", +5 do
|
42
|
+
# assert_difference "Article.count", -1 do
|
43
|
+
# post :something
|
44
|
+
# end
|
41
45
|
# end
|
42
46
|
# end
|
43
|
-
# end
|
44
47
|
#
|
45
48
|
# you can *now* write:
|
46
49
|
#
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
+
# assert_difference "Article.count" => 1, "assigns(:article).comments(:reload).size" => 1, "Article.count" => -1 do
|
51
|
+
# post :something
|
52
|
+
# end
|
53
|
+
#
|
54
|
+
# @param [Array, Hash] expressions array of expressions to evaluate or hash
|
55
|
+
# table of expressions and expected difference.
|
56
|
+
# @param [Integer] difference expected difference when using an array or single expression.
|
57
|
+
# @param [String, nil] message error message to display. One would be constructed if nil.
|
50
58
|
def assert_difference(expressions, difference = 1, message = nil, &block)
|
51
59
|
b = block.send(:binding)
|
52
60
|
if !expressions.is_a? Hash
|
metadata
CHANGED
@@ -1,90 +1,66 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: assert_difference
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
13
|
-
-
|
7
|
+
authors:
|
8
|
+
- J. Pablo Fernández
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-08-24 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: yard
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70137295197880 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :development
|
34
|
-
|
35
|
-
|
36
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70137295197880
|
25
|
+
description: Better assert_difference than Rails by providing a more compact and readable
|
26
|
+
syntax through hashes. For some more information read http://pupeno.com/blog/better-assert-difference.
|
27
|
+
email:
|
28
|
+
- pupeno@pupeno.com
|
37
29
|
executables: []
|
38
|
-
|
39
30
|
extensions: []
|
40
|
-
|
41
|
-
|
42
|
-
- LICENSE
|
43
|
-
- README.rdoc
|
44
|
-
files:
|
45
|
-
- .document
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
46
33
|
- .gitignore
|
34
|
+
- Gemfile
|
47
35
|
- LICENSE
|
48
|
-
- README.
|
36
|
+
- README.md
|
49
37
|
- Rakefile
|
50
|
-
-
|
38
|
+
- assert_difference.gemspec
|
51
39
|
- lib/assert_difference.rb
|
52
40
|
- test/helper.rb
|
53
41
|
- test/test_assert_difference.rb
|
54
|
-
has_rdoc: true
|
55
42
|
homepage: http://github.com/pupeno/assert_difference
|
56
43
|
licenses: []
|
57
|
-
|
58
44
|
post_install_message:
|
59
|
-
rdoc_options:
|
60
|
-
|
61
|
-
require_paths:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
62
47
|
- lib
|
63
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
49
|
none: false
|
65
|
-
requirements:
|
66
|
-
- -
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
|
69
|
-
|
70
|
-
- 0
|
71
|
-
version: "0"
|
72
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
55
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
segments:
|
79
|
-
- 0
|
80
|
-
version: "0"
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.3.6
|
81
60
|
requirements: []
|
82
|
-
|
83
|
-
|
84
|
-
rubygems_version: 1.3.7
|
61
|
+
rubyforge_project: assert_difference
|
62
|
+
rubygems_version: 1.8.6
|
85
63
|
signing_key:
|
86
64
|
specification_version: 3
|
87
|
-
summary:
|
88
|
-
test_files:
|
89
|
-
- test/helper.rb
|
90
|
-
- test/test_assert_difference.rb
|
65
|
+
summary: An improved assert_difference
|
66
|
+
test_files: []
|
data/.document
DELETED
data/README.rdoc
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
= assert_difference
|
2
|
-
|
3
|
-
Better assert_difference than Rails by providing a more compact and readable
|
4
|
-
syntax through hashes. Instead of writing:
|
5
|
-
|
6
|
-
assert_difference "Article.count" do
|
7
|
-
assert_difference "assigns(:article).comments(:reload).size" do
|
8
|
-
assert_difference "Article.count", -1 do
|
9
|
-
post :something
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
you can *now* write:
|
15
|
-
|
16
|
-
assert_difference "Article.count" => 1, "assigns(:article).comments(:reload).size" => 1, "Article.count" => -1 do
|
17
|
-
post :something
|
18
|
-
end
|
19
|
-
|
20
|
-
For some more information read http://pupeno.com/blog/better-assert-difference
|
21
|
-
|
22
|
-
== Note on Patches/Pull Requests
|
23
|
-
|
24
|
-
* Fork the project.
|
25
|
-
* Make your feature addition or bug fix.
|
26
|
-
* Add tests for it. This is important so I don't break it in a
|
27
|
-
future version unintentionally.
|
28
|
-
* Commit, do not mess with rakefile, version, or history.
|
29
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
30
|
-
* Send me a pull request. Bonus points for topic branches.
|
31
|
-
|
32
|
-
== Copyright
|
33
|
-
|
34
|
-
Copyright (c) 2010 José Pablo Fernández. See LICENSE for details.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.0
|