insist 0.0.2 → 0.0.3

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.
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+ script: rspec
data/insist.gemspec CHANGED
@@ -2,7 +2,7 @@ Gem::Specification.new do |spec|
2
2
  files = %x{git ls-files}.split("\n")
3
3
 
4
4
  spec.name = "insist"
5
- spec.version = "0.0.2"
5
+ spec.version = "0.0.3"
6
6
  spec.summary = "insist"
7
7
  spec.description = "insist"
8
8
  spec.license = "none chosen yet"
data/lib/insist.rb CHANGED
@@ -3,9 +3,10 @@ require "insist/namespace"
3
3
  require "insist/assert"
4
4
  require "insist/comparators"
5
5
  require "insist/enumerables"
6
- require "insist/raises"
7
6
  require "insist/failure"
8
7
  require "insist/nil"
8
+ require "insist/predicates"
9
+ require "insist/raises"
9
10
 
10
11
  # Insist on correctness.
11
12
  #
@@ -26,6 +27,7 @@ class Insist
26
27
  include Insist::Nil
27
28
  include Insist::Assert
28
29
  include Insist::Raises
30
+ include Insist::Predicates
29
31
 
30
32
  # Create a new insist with a block.
31
33
  #
@@ -0,0 +1,30 @@
1
+ require "insist/namespace"
2
+ require "insist/assert"
3
+
4
+ module Insist::Predicates
5
+ include Insist::Assert
6
+ PREDICATE_METHOD_RE = /\?$/
7
+
8
+ def respond_to?(method)
9
+ assert(value.respond_to?(method),
10
+ "#{value} does not respond to the '#{method}' method")
11
+ end # def respond_to?
12
+
13
+ # Pass through any 'foo?' style method calls to the 'value'
14
+ # and fail if the the return is false.
15
+ def method_missing(m, *args)
16
+ # If this is a predicate method (ends in question mark)
17
+ # call it on the value and assert truthiness.
18
+ if PREDICATE_METHOD_RE.match(m.to_s)
19
+ insist { value }.respond_to?(m)
20
+
21
+ # call the method, like .empty?, result must be truthy.
22
+ result = value.send(m, *args)
23
+ assert(result, "#{value.inspect}##{m} expected to return a truthy " \
24
+ "value, but returned #{value.inspect}")
25
+ return result
26
+ else
27
+ return super(m, *args)
28
+ end
29
+ end # def method_missing
30
+ end # module Insist::Predicates
@@ -0,0 +1,41 @@
1
+ require "spec_setup"
2
+ require "insist"
3
+ require "insist/predicates"
4
+
5
+ # The predicates feature will delegateany predicate method calls (ones ending
6
+ # in "?") to the block value and fail if the return is false.
7
+ describe Insist::Predicates do
8
+ describe "#respond_to?" do
9
+ subject do
10
+ insist { [1, 2, 3] }
11
+ end
12
+
13
+ it "should be OK if the #value responds to a given method" do
14
+ subject.respond_to?(:[])
15
+ subject.respond_to?(:to_a)
16
+ subject.respond_to?(:each)
17
+ end
18
+
19
+ it "should fail if the #value does not respond to a given method" do
20
+ insist { subject.respond_to?(:SOME_INVALID_METHOD) }.fails
21
+ end
22
+
23
+ it "should fail if the respond_to? is invoked incorrectly" do
24
+ insist { subject.respond_to? }.raises(ArgumentError)
25
+ end
26
+ end # #respond_to?
27
+
28
+ describe "#empty?" do
29
+ it "should be OK if the #value.empty? returns true" do
30
+ insist { [] }.empty?
31
+ insist { {} }.empty?
32
+ insist { "" }.empty?
33
+ end
34
+
35
+ it "should fail if the #value.empty? returns a false" do
36
+ insist { insist { [1] }.empty? }.fails
37
+ insist { insist { { :foo => :bar } }.empty? }.fails
38
+ insist { insist { "hello" }.empty? }.fails
39
+ end
40
+ end # #empty?
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cabin
16
- requirement: &18578060 !ruby/object:Gem::Requirement
16
+ requirement: &12960960 !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: :runtime
23
23
  prerelease: false
24
- version_requirements: *18578060
24
+ version_requirements: *12960960
25
25
  description: insist
26
26
  email:
27
27
  - jls@semicomplete.com
@@ -31,6 +31,7 @@ extra_rdoc_files: []
31
31
  files:
32
32
  - .batcave/manifest
33
33
  - .gitignore
34
+ - .travis.yml
34
35
  - Gemfile
35
36
  - Makefile
36
37
  - README.md
@@ -42,11 +43,13 @@ files:
42
43
  - lib/insist/failure.rb
43
44
  - lib/insist/namespace.rb
44
45
  - lib/insist/nil.rb
46
+ - lib/insist/predicates.rb
45
47
  - lib/insist/raises.rb
46
48
  - notify-failure.sh
47
49
  - spec/insist/comparators_spec.rb
48
50
  - spec/insist/enumerables_spec.rb
49
51
  - spec/insist/nil_spec.rb
52
+ - spec/insist/predicates_spec.rb
50
53
  - spec/insist_spec.rb
51
54
  - spec/spec_setup.rb
52
55
  - test/all.rb