grumpy_old_man 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ group :test do
4
+ gem "rspec"
5
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ rspec (2.11.0)
6
+ rspec-core (~> 2.11.0)
7
+ rspec-expectations (~> 2.11.0)
8
+ rspec-mocks (~> 2.11.0)
9
+ rspec-core (2.11.1)
10
+ rspec-expectations (2.11.2)
11
+ diff-lcs (~> 1.1.3)
12
+ rspec-mocks (2.11.2)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ rspec
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Asserts for RSpec
2
+
3
+ GrumpyOldMan is an RSpec shim that provides old school assert methods.
4
+
5
+ ![Grumpy Old Man GEM](http://hopsoft.github.com/grumpy_old_man/images/clint-eastwood.jpg)
6
+
7
+ It adds the following methods to RSpec without compromising any of RSpecs awesomeness.
8
+
9
+ * `assert`
10
+ * `assert_equal`
11
+ * `assert_raise`
12
+
13
+ Yes you really can have your cake and eat it too!
14
+
15
+ ---
16
+
17
+ I love several things about RSpec.
18
+
19
+ * Its beautiful output from the test runner
20
+ * Its declarative approach to writing tests... well at least the outer wrapper e.g. `describe Thing it 'should do stuff'`
21
+
22
+ I lament the fact that the rest of RSpec is an over engineered solution to a simple problem.
23
+ `assert true`
24
+
25
+ ---
26
+
27
+ My contention is that its better to write tests in the same manner you write the app.
28
+ This approach does away with the context switching between app syntax and a wonky DSL confined to the test suite.
29
+
30
+ It also lowers the barrier to entry.
31
+
32
+ Consider the following example from the RSpec docs.
33
+
34
+ ```ruby
35
+ expect(order.total).to eq(Money.new(5.55, :USD))
36
+ ```
37
+
38
+ Rewritten with GrumpyOldMan.
39
+ ```ruby
40
+ assert order.total == Money.new(5.55, :USD)
41
+ # or ...
42
+ assert_equal order.total, Money.new(5.55, :USD)
43
+ ```
44
+
45
+ Asserts allow me to write code that more closely resembles the app logic itself... which feels more natural.
46
+
47
+ ## Usage
48
+
49
+ Simply include GrumpyOldMan in your spec/test like so.
50
+
51
+ ```ruby
52
+ describe Thing
53
+ include GrumpyOldMan
54
+
55
+ it "should feel good" do
56
+ assert true
57
+ end
58
+
59
+ it "should be balanced" do
60
+ assert_equal true, true
61
+ end
62
+
63
+ it "should be exceptional" do
64
+ assert_raise(Exception) { raise }
65
+ end
66
+
67
+ end
68
+ ```
69
+
70
+ You might not agree, but I'm sticking with my old fashioned assert.
71
+
72
+ **Now get off my lawn!**
73
+
74
+ <a href="https://github.com/hopsoft/grumpy_old_man"><img style="position: fixed; top: 0; right: 0; border: 0; z-index: 9999;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a>
@@ -0,0 +1,51 @@
1
+ # An RSpec shim that provides old school assert methods.
2
+ # My contention is that its better to write tests in the same fashion that you write the app.
3
+ # This approach is faster since it does away with the need to context switch
4
+ # between app logic and a wonky DSL provided by the test suite.
5
+ # The barrier to entry is also lower for the unitiated RSpec user.
6
+ #
7
+ # Consider the following example from the RSpec docs.
8
+ # expect(order.total).to eq(Money.new(5.55, :USD))
9
+ #
10
+ # Rewritten with GrumpyOldMan.
11
+ # assert_equal order.total, Money.new(5.55, :USD)
12
+ #
13
+ # The traditional assert allows me to write the same style of code in both the app and my tests.
14
+ # This feels much more natural to me. You might not agree, but I'm sticking to my old fashioned assert.
15
+ module GrumpyOldMan
16
+
17
+ # A simple assert for RSpec so folks don't have to learn a wonky DSL
18
+ # and monkeypatched object methods that eventually boil down to a basic "assert" anyway.
19
+ #
20
+ # @example
21
+ # assert(true)
22
+ #
23
+ # @example
24
+ # assert { true.to_s == "true" }
25
+ #
26
+ # @param [Object] arg An optional arg to assert as equal to true.
27
+ def assert(arg=nil)
28
+ if block_given?
29
+ assert_equal(yield, true)
30
+ else
31
+ assert_equal(arg, true)
32
+ end
33
+ end
34
+
35
+ # A basic assert helper that tests for Object equality.
36
+ # Tests for object equivalence rather than object identity since this is sufficient for 99.9% of tests.
37
+ #
38
+ # @param [Objecct] obj The Object to compare.
39
+ # @param [Objecct] expected The expected value.
40
+ def assert_equal(obj, expected)
41
+ obj.should == expected
42
+ end
43
+
44
+ # A basic assert helper that ensures an Error was raised.
45
+ # @param [Class] ex The expected Exception class.
46
+ def assert_raise(ex, &block)
47
+ Proc.new(&block).should raise_error(ex)
48
+ end
49
+
50
+ end
51
+
@@ -0,0 +1,21 @@
1
+ require File.join(File.dirname(__FILE__), "..", "lib", "grumpy_old_man")
2
+
3
+ describe RSpec do
4
+ # we eat our dog food
5
+ include GrumpyOldMan
6
+
7
+ it "should support assert with GrumpyOldMan" do
8
+ assert self.respond_to? :assert
9
+ end
10
+
11
+ it "should support assert_equal with GrumpyOldMan" do
12
+ assert_equal true, self.respond_to?(:assert)
13
+ end
14
+
15
+ it "should support assert_raise with GrumpyOldMan" do
16
+ assert self.respond_to?(:assert_raise)
17
+ assert_raise(Exception) { raise }
18
+ end
19
+
20
+ end
21
+
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grumpy_old_man
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nathan Hopkins
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-21 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! " Do you like RSpec's delcarative describe statements but hate its
15
+ wonky DSL that monkey patches BasicObject?\n Do you want to write tests without
16
+ learning all of RSpec's matchers and expectations?\n Do you prefer simple asserts
17
+ in your test suite?\n Welcome home my friend, GrumpyOldMan is for you.\n"
18
+ email:
19
+ - natehop@gmail.com
20
+ executables: []
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - lib/grumpy_old_man.rb
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - README.md
28
+ - spec/grumpy_old_man_spec.rb
29
+ homepage: https://github.com/hopsoft/grumpy_old_man
30
+ licenses:
31
+ - MIT
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 1.8.24
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: Asserts for RSpec.
54
+ test_files: []