assert_difference 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/README.md +8 -3
  2. data/Rakefile +29 -19
  3. data/lib/assert_difference.rb +13 -3
  4. metadata +6 -5
data/README.md CHANGED
@@ -43,8 +43,8 @@ and to use it with RSpec:
43
43
 
44
44
  For more information read http://pupeno.com/blog/better-assert-difference
45
45
 
46
- Note on Patches/Pull Requests
47
- -----------------------------
46
+ Notes on contributing
47
+ ---------------------
48
48
 
49
49
  * Fork the project.
50
50
  * Make your feature addition or bug fix.
@@ -53,8 +53,13 @@ Note on Patches/Pull Requests
53
53
  * Commit, do not mess with rakefile, version, or history.
54
54
  (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)
55
55
  * Send me a pull request. Bonus points for topic branches.
56
+ * Document any new options and verify the documentation looks correct by running:
57
+
58
+ yard server --reload
59
+
60
+ and going to http://localhost:8808
56
61
 
57
62
  Copyright
58
63
  ---------
59
64
 
60
- Copyright (c) 2010, 2011, José Pablo Fernández. See LICENSE for details.
65
+ Copyright (c) 2010, 2011, 2012 José Pablo Fernández. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,29 +1,39 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  # Copyright © 2011, José Pablo Fernández
3
3
 
4
- task :default => :test
4
+ require "rake"
5
+ require "rake/testtask"
6
+ require "bundler/gem_tasks"
5
7
 
6
- require "bundler"
7
- Bundler::GemHelper.install_tasks
8
+ desc "Default: run unit tests."
9
+ task :default => :test
8
10
 
9
- require "rake/testtask"
10
- Rake::TestTask.new(:test) do |test|
11
- test.libs << "lib" << "test"
12
- test.pattern = "test/**/test_*.rb"
13
- test.verbose = true
11
+ desc "Test the table_builder plugin."
12
+ Rake::TestTask.new(:test) do |t|
13
+ t.libs << "lib"
14
+ t.pattern = "test/**/*_test.rb"
15
+ t.verbose = true
14
16
  end
15
17
 
16
- require "rcov/rcovtask"
17
- Rcov::RcovTask.new do |test|
18
- test.libs << "test"
19
- test.pattern = "test/**/test_*.rb"
20
- test.verbose = true
18
+ begin
19
+ require "rcov/rcovtask"
20
+ Rcov::RcovTask.new do |test|
21
+ test.libs << "test"
22
+ test.pattern = "test/**/test_*.rb"
23
+ test.verbose = true
24
+ end
25
+ rescue LoadError => e
26
+ puts "rcov is not installed, oh well"
21
27
  end
22
28
 
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"
29
+ begin
30
+ require "yard"
31
+ YARD::Rake::YardocTask.new do |yard|
32
+ # Use Markdown for documentation.
33
+ yard.options << "--markup" << "markdown"
34
+ # Extra file(s).
35
+ yard.options << "-" << "LICENSE"
36
+ end
37
+ rescue LoadError => e
38
+ puts "yard is not installed, oh well"
29
39
  end
@@ -1,8 +1,8 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # Copyright © 2010, 2011, José Pablo Fernández
2
+ # Copyright © 2010, 2011, 2012 José Pablo Fernández
3
3
 
4
4
  module AssertDifference
5
- VERSION = "0.3.1" unless defined?(::AssertDifference::VERSION)
5
+ VERSION = "0.4.0" unless defined?(::AssertDifference::VERSION)
6
6
 
7
7
  # Test numeric difference between the return value of an expression as a result of what is evaluated
8
8
  # in the yielded block.
@@ -51,10 +51,18 @@ module AssertDifference
51
51
  # post :something
52
52
  # end
53
53
  #
54
+ # the results of the block is the result of the assert, so you can write
55
+ #
56
+ # email = assert_difference "ActionMailer::Base.deliveries.count" => +1 do
57
+ # Mailer.reset_password_email(@user).deliver
58
+ # end
59
+ # assert_equal [@user.email], email.to
60
+ #
54
61
  # @param [Array, Hash] expressions array of expressions to evaluate or hash
55
62
  # table of expressions and expected difference.
56
63
  # @param [Integer] difference expected difference when using an array or single expression.
57
64
  # @param [String, nil] message error message to display. One would be constructed if nil.
65
+ # @return whatever the block returned
58
66
  def assert_difference(expressions, difference = 1, message = nil, &block)
59
67
  b = block.send(:binding)
60
68
  if !expressions.is_a? Hash
@@ -66,12 +74,14 @@ module AssertDifference
66
74
  before = {}
67
75
  expressions.each { |exp, _| before[exp] = eval(exp, b) }
68
76
 
69
- yield
77
+ result = yield
70
78
 
71
79
  expressions.each do |exp, diff|
72
80
  error = "#{exp.inspect} didn't change by #{diff}"
73
81
  error = "#{message}.\n#{error}" if message
74
82
  assert_equal(before[exp] + diff, eval(exp, b), error)
75
83
  end
84
+
85
+ return result
76
86
  end
77
87
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assert_difference
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-25 00:00:00.000000000Z
12
+ date: 2012-02-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yard
16
- requirement: &70098770379360 !ruby/object:Gem::Requirement
16
+ requirement: &70228130478420 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70098770379360
24
+ version_requirements: *70228130478420
25
25
  description: Better assert_difference than Rails by providing a more compact and readable
26
26
  syntax through hashes. For some more information read http://pupeno.com/blog/better-assert-difference.
27
27
  email:
@@ -59,8 +59,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  version: 1.3.6
60
60
  requirements: []
61
61
  rubyforge_project: assert_difference
62
- rubygems_version: 1.8.6
62
+ rubygems_version: 1.8.10
63
63
  signing_key:
64
64
  specification_version: 3
65
65
  summary: An improved assert_difference
66
66
  test_files: []
67
+ has_rdoc: