insist 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ ---
2
+ things:
3
+ ruby:
4
+ args:
5
+ - insist
@@ -0,0 +1,2 @@
1
+ .yardoc
2
+ coverage
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ source :rubygems
@@ -0,0 +1,46 @@
1
+ GEMSPEC=$(shell ls *.gemspec)
2
+ VERSION=$(shell awk -F\" '/spec.version/ { print $$2 }' $(GEMSPEC))
3
+ NAME=$(shell awk -F\" '/spec.name/ { print $$2 }' $(GEMSPEC))
4
+ GEM=$(NAME)-$(VERSION).gem
5
+
6
+ .PHONY: test
7
+ test:
8
+ sh notify-failure.sh ruby test/all.rb
9
+
10
+ .PHONY: testloop
11
+ testloop:
12
+ while true; do \
13
+ $(MAKE) test; \
14
+ $(MAKE) wait-for-changes; \
15
+ done
16
+
17
+ .PHONY: serve-coverage
18
+ serve-coverage:
19
+ cd coverage; python -mSimpleHTTPServer
20
+
21
+ .PHONY: wait-for-changes
22
+ wait-for-changes:
23
+ -inotifywait --exclude '\.swp' -e modify $$(find $(DIRS) -name '*.rb'; find $(DIRS) -type d)
24
+
25
+ .PHONY: package
26
+ package: | $(GEM)
27
+
28
+ .PHONY: gem
29
+ gem: $(GEM)
30
+
31
+ $(GEM):
32
+ gem build $(GEMSPEC)
33
+
34
+ .PHONY: test-package
35
+ test-package: $(GEM)
36
+ # Sometimes 'gem build' makes a faulty gem.
37
+ gem unpack $(GEM)
38
+ rm -rf ftw-$(VERSION)/
39
+
40
+ .PHONY: publish
41
+ publish: test-package
42
+ gem push $(GEM)
43
+
44
+ .PHONY: install
45
+ install: $(GEM)
46
+ gem install $(GEM)
data/README ADDED
File without changes
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |spec|
2
+ files = %x{git ls-files}.split("\n")
3
+
4
+ spec.name = "insist"
5
+ spec.version = "0.0.1"
6
+ spec.summary = "insist"
7
+ spec.description = "insist"
8
+ spec.license = "none chosen yet"
9
+
10
+ # Note: You should set the version explicitly.
11
+ spec.add_dependency "cabin", ">0" # for logging. apache 2 license
12
+ spec.files = files
13
+ spec.require_paths << "lib"
14
+ spec.bindir = "bin"
15
+
16
+ spec.authors = ["Jordan Sissel"]
17
+ spec.email = ["jls@semicomplete.com"]
18
+ #spec.homepage = "..."
19
+ end
20
+
@@ -0,0 +1,53 @@
1
+ require "insist/namespace"
2
+
3
+ require "insist/assert"
4
+ require "insist/comparators"
5
+ require "insist/raises"
6
+ require "insist/failure"
7
+ require "insist/nil"
8
+
9
+ # Insist on correctness.
10
+ #
11
+ #
12
+ # Example:
13
+ #
14
+ # data = { "hello" => "world" }
15
+ # insist { data["hello"] } == "world"
16
+ #
17
+ # This class aims to work similarly to how rspec's "should" stuff does, but
18
+ # instead of molesting Object allows you to neatly wrap values with blocks
19
+ # while still checking for expected values.
20
+ class Insist
21
+ class Failure < StandardError; end
22
+
23
+ include Insist::Comparators
24
+ include Insist::Nil
25
+ include Insist::Assert
26
+ include Insist::Raises
27
+
28
+ # Create a new insist with a block.
29
+ #
30
+ # Example:
31
+ #
32
+ # Insist.new { value }
33
+ #
34
+ # Better:
35
+ #
36
+ # insist { value }
37
+ def initialize(&block)
38
+ @callback = block
39
+ end
40
+
41
+ def value
42
+ # TODO(sissel): make caching the value optional
43
+ @value ||= @callback.call
44
+ return @value
45
+ end
46
+ end # class Insist
47
+
48
+ module Kernel
49
+ # A shortcut to 'Insist.new'
50
+ def insist(&block)
51
+ return Insist.new(&block)
52
+ end
53
+ end
@@ -0,0 +1,10 @@
1
+
2
+ module Insist::Assert
3
+ # Assert something is true.
4
+ #
5
+ # This will raise Insist::Failure with the given message if the 'truthy'
6
+ # value is false.
7
+ def assert(truthy, message)
8
+ raise Insist::Failure.new(message) if !truthy
9
+ end # def assert
10
+ end # module Insist::Assert
@@ -0,0 +1,45 @@
1
+
2
+ # Provides the '==' assertion method.
3
+ #
4
+ # Example:
5
+ #
6
+ # insist { "foo" } == "foo"
7
+ module Insist::Comparators
8
+ include Insist::Assert
9
+
10
+ # value == expected
11
+ def ==(expected)
12
+ assert(value == expected,
13
+ "Expected #{expected.inspect}, but got #{value.inspect}")
14
+ end # def ==
15
+
16
+ # value <= expected
17
+ def <=(expected)
18
+ assert(value <= expected,
19
+ "Expected #{value.inspect} <= #{expected.inspect}")
20
+ end # def <=
21
+
22
+ # value >= expected
23
+ def >=(expected)
24
+ assert(value >= expected,
25
+ "Expected #{value.inspect} >= #{expected.inspect}")
26
+ end # def >=
27
+
28
+ # value > expected
29
+ def >(expected)
30
+ assert(value > expected,
31
+ "Expected #{value.inspect} > #{expected.inspect}")
32
+ end # def >
33
+
34
+ # value < expected
35
+ def <(expected)
36
+ assert(value < expected,
37
+ "Expected #{value.inspect} < #{expected.inspect}")
38
+ end # def <
39
+
40
+ # value != expected
41
+ def !=(expected)
42
+ assert(value != expected,
43
+ "Expected #{value.inspect} != #{expected.inspect}")
44
+ end # def !=
45
+ end # module Insist::Comparators
@@ -0,0 +1,4 @@
1
+ # A failure. This is raised if an `insist` check fails.
2
+ class Insist::Failure < StandardError
3
+ # Nothing here.
4
+ end
@@ -0,0 +1 @@
1
+ class Insist; end
@@ -0,0 +1,7 @@
1
+
2
+ module Insist::Nil
3
+ # Assert nil
4
+ def nil?
5
+ assert(value.nil?, "Expected nil, got #{@value.inspect}")
6
+ end # def nil?
7
+ end # module Insist::Nil
@@ -0,0 +1,14 @@
1
+
2
+ module Insist::Raises
3
+ # Assert raises
4
+ def raises(exception_class)
5
+ begin
6
+ value
7
+ rescue exception_class => e
8
+ return # We're OK
9
+ end
10
+
11
+ assert(false,
12
+ "Expected exception '#{exception_class}' but none was raised")
13
+ end # def raises
14
+ end # module Insist::Raises
@@ -0,0 +1,15 @@
1
+ #!/bin/sh
2
+
3
+ "$@"
4
+ status=$?
5
+
6
+ if [ ! -z "$TMUX" ] ; then
7
+ if [ "$status" -ne 0 ] ; then
8
+ tmux display-message "Tests Fail"
9
+ else
10
+ tmux display-message "Tests OK"
11
+ fi
12
+ fi
13
+
14
+ exit $status
15
+
@@ -0,0 +1,42 @@
1
+ require "spec_setup"
2
+ require "insist"
3
+
4
+ describe Insist::Comparators do
5
+ subject do
6
+ Insist.new { 30 }
7
+ end
8
+
9
+ describe "#==" do
10
+ it "should be OK if the #value is equal" do
11
+ subject == 30
12
+ end
13
+
14
+ it "should fail if the #value is not equal" do
15
+ insist { subject == 0 }.raises(Insist::Failure)
16
+ end
17
+ end
18
+
19
+ describe "#<=" do
20
+ it "should be OK if the #value is less than or equal" do
21
+ larger = subject.value + 1
22
+ subject <= larger
23
+ end
24
+
25
+ it "should fail if the #value is greater" do
26
+ smaller = subject.value - 1
27
+ insist { subject <= smaller }.raises(Insist::Failure)
28
+ end
29
+ end
30
+
31
+ describe "#>=" do
32
+ it "should be OK if the #value is greater than or equal" do
33
+ smaller = subject.value - 1
34
+ subject >= smaller
35
+ end
36
+
37
+ it "should fail if the #value is lesser" do
38
+ larger = subject.value + 1
39
+ insist { subject >= larger }.raises(Insist::Failure)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_setup"
2
+ require "insist"
3
+
4
+ describe Insist::Nil do
5
+ describe "#nil?" do
6
+ it "should be OK if the #value is nil" do
7
+ insist { nil }.nil?
8
+ end
9
+
10
+ it "should fail if the #value is not nil" do
11
+ insist do
12
+ insist { "not nil" }.nil?
13
+ end.raises(Insist::Failure)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_setup"
2
+ require "insist"
3
+
4
+ describe Insist do
5
+ subject do
6
+ Insist.new { "Hello world" }
7
+ end
8
+
9
+ describe "#value" do
10
+ it "should return the block value" do
11
+ insist { subject.value } == "Hello world"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1 @@
1
+ $: << File.join(File.dirname(File.dirname(__FILE__)), "lib")
@@ -0,0 +1,24 @@
1
+ require "rubygems"
2
+ require "minitest/spec"
3
+ require "minitest/autorun"
4
+
5
+ # Get coverage report
6
+ require "simplecov"
7
+ SimpleCov.start
8
+
9
+ # Add '../lib' to the require path.
10
+ $: << File.join(File.dirname(__FILE__), "..", "lib")
11
+
12
+ def use(path)
13
+ puts "Loading tests from #{path}"
14
+ require File.expand_path(path)
15
+ end
16
+
17
+ dirname = File.dirname(__FILE__)
18
+ use File.join(dirname, "docs.rb")
19
+
20
+ # Load tests from ./*/**/*.rb (usually ./libraryname/....)
21
+ glob = File.join(dirname, "*", "**", "*.rb")
22
+ Dir.glob(glob).each do |path|
23
+ use path
24
+ end
@@ -0,0 +1,40 @@
1
+ require "rubygems"
2
+ require "yard"
3
+ require File.join(File.expand_path(File.dirname(__FILE__)), "testing")
4
+
5
+ describe "documentation tests" do
6
+ before do
7
+ # Use YARD to parse all ruby files found in '../lib'
8
+ libdir = File.join(File.dirname(__FILE__), "..", "lib")
9
+ YARD::Registry.load(Dir.glob(File.join(libdir, "**", "*.rb")))
10
+ @registry = YARD::Registry.all
11
+ end
12
+
13
+ test "All classes, methods, modules, and constants must be documented" do
14
+ # Note, the 'find the undocumented things' code here is
15
+ # copied mostly from: YARD 0.7.5's lib/yard/cli/stats.rb
16
+ #
17
+ # Find all undocumented classes, modules, and constants
18
+ undocumented = @registry.select do |o|
19
+ [:class, :module, :constant].include?(o.type) && o.docstring.blank?
20
+ end
21
+
22
+ # Find all undocumented methods
23
+ methods = @registry.select { |m| m.type == :method }
24
+ methods.reject! { |m| m.is_alias? || !m.is_explicit? }
25
+ undocumented += methods.select do |m|
26
+ m.docstring.blank? && !m.overridden_method
27
+ end
28
+
29
+ if (undocumented.length > 0)
30
+ message = ["The following are not documented"]
31
+ undocumented.each do |o|
32
+ message << "* #{o.type.to_s} #{o.to_s} <#{o.file}:#{o.line}>"
33
+ end
34
+
35
+ flunk(message.join("\n"))
36
+ else
37
+ pass
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,14 @@
1
+ require "rubygems"
2
+ require "minitest/spec"
3
+
4
+ # Add '../lib' to the require path.
5
+ $: << File.join(File.dirname(__FILE__), "..", "lib")
6
+
7
+ # I don't really like monkeypatching, but whatever, this is probably better
8
+ # than overriding the 'describe' method.
9
+ class MiniTest::Spec
10
+ class << self
11
+ # 'it' sounds wrong, call it 'test'
12
+ alias :test :it
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: insist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jordan Sissel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: cabin
16
+ requirement: &13980620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>'
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *13980620
25
+ description: insist
26
+ email:
27
+ - jls@semicomplete.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .batcave/manifest
33
+ - .gitignore
34
+ - Gemfile
35
+ - Makefile
36
+ - README
37
+ - insist.gemspec
38
+ - lib/insist.rb
39
+ - lib/insist/assert.rb
40
+ - lib/insist/comparators.rb
41
+ - lib/insist/failure.rb
42
+ - lib/insist/namespace.rb
43
+ - lib/insist/nil.rb
44
+ - lib/insist/raises.rb
45
+ - notify-failure.sh
46
+ - spec/insist/comparators_spec.rb
47
+ - spec/insist/nil_spec.rb
48
+ - spec/insist_spec.rb
49
+ - spec/spec_setup.rb
50
+ - test/all.rb
51
+ - test/docs.rb
52
+ - test/testing.rb
53
+ homepage:
54
+ licenses:
55
+ - none chosen yet
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.10
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: insist
79
+ test_files: []
80
+ has_rdoc: