insist 0.0.1 → 0.0.2

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/Gemfile CHANGED
@@ -1 +1,7 @@
1
1
  source :rubygems
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "rspec", "~> 2.8.0"
7
+ end
data/Makefile CHANGED
@@ -44,3 +44,7 @@ publish: test-package
44
44
  .PHONY: install
45
45
  install: $(GEM)
46
46
  gem install $(GEM)
47
+
48
+ .PHONY: clean
49
+ clean:
50
+ -rm -rf .yardoc $(GEM)
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # insist { on readable assertions }
2
+
3
+ I like rspec, but I don't like the '#should' junk. It scratches me the wrong
4
+ way, I guess. I find this to be an unreadable mess:
5
+
6
+ # yuck, if you ask me.
7
+ somevalue.should eq(0)
8
+
9
+ On the flip side, I really like the idea (make tests read like english).
10
+
11
+ So instead of slapping '#should' on all objects and doing weird stuff like
12
+ `expect { block }.to raise_error(thing)`, I just use blocks for everything in a
13
+ kind of lazy-evaluation wrapping:
14
+
15
+ # Check equality
16
+ insist { value } == 30
17
+
18
+ # Insist an exception is raised
19
+ insist { code }.raises(exception_class)
20
+
21
+ Reads well, I think.
22
+
23
+ ## Most minimal assertions possible
24
+
25
+ Using rspec's 'subject' stuff, you can write tests that are perhaps even more minimal while still being clear.
26
+
27
+ Here's an example test that fails. The subject is an 'insist' object, so you
28
+ can just do the usual '==' and other methods on it:
29
+
30
+ describe "thing" do
31
+ subject { insist { "whoa!" } }
32
+
33
+ it "should be, like, awesome!"
34
+ subject == "awesome!"
35
+ end
36
+ end
37
+
38
+ Running it:
39
+
40
+ Failures:
41
+
42
+ 1) thing should be, like, awesome!
43
+ Failure/Error: subject == "awesome!"
44
+ Insist::Failure:
45
+ Expected "awesome!", but got "whoa!"
46
+ # ./lib/insist/assert.rb:8:in `assert'
47
+ # ./lib/insist/comparators.rb:12:in `=='
48
+ # ./test.rb:5:in `block (2 levels) in <top (required)>'
49
+
50
+ Finished in 0.00208 seconds
51
+ 1 example, 1 failure
52
+
53
+ Failed examples:
54
+
55
+ rspec ./test.rb:4 # thing should be, like, awesome!
56
+
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.1"
5
+ spec.version = "0.0.2"
6
6
  spec.summary = "insist"
7
7
  spec.description = "insist"
8
8
  spec.license = "none chosen yet"
data/lib/insist.rb CHANGED
@@ -2,6 +2,7 @@ require "insist/namespace"
2
2
 
3
3
  require "insist/assert"
4
4
  require "insist/comparators"
5
+ require "insist/enumerables"
5
6
  require "insist/raises"
6
7
  require "insist/failure"
7
8
  require "insist/nil"
@@ -21,6 +22,7 @@ class Insist
21
22
  class Failure < StandardError; end
22
23
 
23
24
  include Insist::Comparators
25
+ include Insist::Enumerables
24
26
  include Insist::Nil
25
27
  include Insist::Assert
26
28
  include Insist::Raises
@@ -0,0 +1,14 @@
1
+
2
+ # Provides assertions for enumerable-ish methods
3
+ #
4
+ # Example:
5
+ #
6
+ # insist { "foo" } == "foo"
7
+ module Insist::Enumerables
8
+ include Insist::Assert
9
+
10
+ def include?(item)
11
+ assert(value.include?(item),
12
+ "Expected #{item.inspect} in #{value.inspect}")
13
+ end
14
+ end
data/lib/insist/raises.rb CHANGED
@@ -11,4 +11,9 @@ module Insist::Raises
11
11
  assert(false,
12
12
  "Expected exception '#{exception_class}' but none was raised")
13
13
  end # def raises
14
+
15
+ # Asserts a failure
16
+ def fails
17
+ raises(Insist::Failure)
18
+ end # def fails
14
19
  end # module Insist::Raises
@@ -12,7 +12,7 @@ describe Insist::Comparators do
12
12
  end
13
13
 
14
14
  it "should fail if the #value is not equal" do
15
- insist { subject == 0 }.raises(Insist::Failure)
15
+ insist { subject == 0 }.fails
16
16
  end
17
17
  end
18
18
 
@@ -22,21 +22,61 @@ describe Insist::Comparators do
22
22
  subject <= larger
23
23
  end
24
24
 
25
+ it "should be OK if the #value is equal" do
26
+ subject >= subject.value
27
+ end
28
+
25
29
  it "should fail if the #value is greater" do
26
30
  smaller = subject.value - 1
27
- insist { subject <= smaller }.raises(Insist::Failure)
31
+ insist { subject <= smaller }.fails
28
32
  end
29
33
  end
30
34
 
31
35
  describe "#>=" do
32
- it "should be OK if the #value is greater than or equal" do
36
+ it "should be OK if the #value is greater than" do
33
37
  smaller = subject.value - 1
34
38
  subject >= smaller
35
39
  end
36
40
 
41
+ it "should be OK if the #value is equal" do
42
+ subject >= subject.value
43
+ end
44
+
45
+ it "should fail if the #value is lesser" do
46
+ larger = subject.value + 1
47
+ insist { subject >= larger }.fails
48
+ end
49
+ end
50
+
51
+ describe "#<" do
52
+ it "should be OK if the #value is less than" do
53
+ larger = subject.value + 1
54
+ subject < larger
55
+ end
56
+
57
+ it "should fail if the #value is equal" do
58
+ insist { subject < subject.value }.fails
59
+ end
60
+
61
+ it "should fail if the #value is greater" do
62
+ smaller = subject.value - 1
63
+ insist { subject < smaller }.fails
64
+ end
65
+ end
66
+
67
+ describe "#>" do
68
+ it "should be OK if the #value is greater than" do
69
+ smaller = subject.value - 1
70
+ subject > smaller
71
+ end
72
+
73
+ it "should fail if the #value is equal" do
74
+ insist { subject > subject.value }.fails
75
+ end
76
+
37
77
  it "should fail if the #value is lesser" do
38
78
  larger = subject.value + 1
39
- insist { subject >= larger }.raises(Insist::Failure)
79
+ insist { subject > larger }.fails
40
80
  end
41
81
  end
42
82
  end
@@ -0,0 +1,18 @@
1
+ require "spec_setup"
2
+ require "insist"
3
+
4
+ describe Insist::Enumerables do
5
+ subject do
6
+ Insist.new { [1,2,3] }
7
+ end
8
+
9
+ describe "#include?" do
10
+ it "should be OK if the #value includes an item" do
11
+ subject.include?(2)
12
+ end
13
+
14
+ it "should fail if the #value does not include an item" do
15
+ insist { subject.include?(4) }.fails
16
+ end
17
+ end
18
+ end
@@ -10,7 +10,7 @@ describe Insist::Nil do
10
10
  it "should fail if the #value is not nil" do
11
11
  insist do
12
12
  insist { "not nil" }.nil?
13
- end.raises(Insist::Failure)
13
+ end.fails
14
14
  end
15
15
  end
16
16
  end
data/test/docs.rb CHANGED
@@ -11,6 +11,8 @@ describe "documentation tests" do
11
11
  end
12
12
 
13
13
  test "All classes, methods, modules, and constants must be documented" do
14
+ # YARD's parser works best in ruby 1.9.x, so skip 1.8.x
15
+ skip if RUBY_VERSION < "1.9.2"
14
16
  # Note, the 'find the undocumented things' code here is
15
17
  # copied mostly from: YARD 0.7.5's lib/yard/cli/stats.rb
16
18
  #
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.1
4
+ version: 0.0.2
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: 2012-03-08 00:00:00.000000000 Z
12
+ date: 2012-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cabin
16
- requirement: &13980620 !ruby/object:Gem::Requirement
16
+ requirement: &18578060 !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: *13980620
24
+ version_requirements: *18578060
25
25
  description: insist
26
26
  email:
27
27
  - jls@semicomplete.com
@@ -33,17 +33,19 @@ files:
33
33
  - .gitignore
34
34
  - Gemfile
35
35
  - Makefile
36
- - README
36
+ - README.md
37
37
  - insist.gemspec
38
38
  - lib/insist.rb
39
39
  - lib/insist/assert.rb
40
40
  - lib/insist/comparators.rb
41
+ - lib/insist/enumerables.rb
41
42
  - lib/insist/failure.rb
42
43
  - lib/insist/namespace.rb
43
44
  - lib/insist/nil.rb
44
45
  - lib/insist/raises.rb
45
46
  - notify-failure.sh
46
47
  - spec/insist/comparators_spec.rb
48
+ - spec/insist/enumerables_spec.rb
47
49
  - spec/insist/nil_spec.rb
48
50
  - spec/insist_spec.rb
49
51
  - spec/spec_setup.rb
@@ -72,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
74
  version: '0'
73
75
  requirements: []
74
76
  rubyforge_project:
75
- rubygems_version: 1.8.10
77
+ rubygems_version: 1.8.16
76
78
  signing_key:
77
79
  specification_version: 3
78
80
  summary: insist
data/README DELETED
File without changes