insist-1.0.0/0000755000000000000000000000000012537705054011527 5ustar rootrootinsist-1.0.0/spec/0000755000000000000000000000000012537705054012461 5ustar rootrootinsist-1.0.0/spec/insist/0000755000000000000000000000000012537705054013772 5ustar rootrootinsist-1.0.0/spec/insist/reject_spec.rb0000664000000000000000000000052612537705054016612 0ustar rootrootrequire "spec_setup" require "insist" describe Insist::Comparators do subject do reject { [1,2,3] } end describe "#include?" do it "should fail if the include? returns true" do insist { subject.include?(2) }.fails end it "should succeed if include? returns false" do subject.include?(4) end end end insist-1.0.0/spec/insist/enumerables_spec.rb0000664000000000000000000000054712537705054017643 0ustar rootrootrequire "spec_setup" require "insist" describe Insist::Enumerables do subject do Insist.new { [1,2,3] } end describe "#include?" do it "should be OK if the #value includes an item" do subject.include?(2) end it "should fail if the #value does not include an item" do insist { subject.include?(4) }.fails end end end insist-1.0.0/spec/insist/predicates_spec.rb0000664000000000000000000000305612537705054017462 0ustar rootrootrequire "spec_setup" require "insist" require "insist/predicates" # The predicates feature will delegateany predicate method calls (ones ending # in "?") to the block value and fail if the return is false. describe Insist::Predicates do describe "#is_a?" do it "should succeed if value#is_a? returns true" do insist { "some string" }.is_a?(Object) insist { "some string" }.is_a?(String) end it "should fail if value#is_a? returns false" do reject { "some string" }.is_a?(Numeric) reject { "some string" }.is_a?(Fixnum) reject { "some string" }.is_a?(File) end end describe "#respond_to?" do subject do insist { [1, 2, 3] } end it "should be OK if the #value responds to a given method" do subject.respond_to?(:[]) subject.respond_to?(:to_a) subject.respond_to?(:each) end it "should fail if the #value does not respond to a given method" do insist { subject.respond_to?(:SOME_INVALID_METHOD) }.fails end it "should fail if the respond_to? is invoked incorrectly" do insist { subject.respond_to? }.raises(ArgumentError) end end # #respond_to? describe "#empty?" do it "should be OK if the #value.empty? returns true" do insist { [] }.empty? insist { {} }.empty? insist { "" }.empty? end it "should fail if the #value.empty? returns a false" do insist { insist { [1] }.empty? }.fails insist { insist { { :foo => :bar } }.empty? }.fails insist { insist { "hello" }.empty? }.fails end end # #empty? end insist-1.0.0/spec/insist/nil_spec.rb0000664000000000000000000000045312537705054016117 0ustar rootrootrequire "spec_setup" require "insist" describe Insist::Nil do describe "#nil?" do it "should be OK if the #value is nil" do insist { nil }.nil? end it "should fail if the #value is not nil" do insist do insist { "not nil" }.nil? end.fails end end end insist-1.0.0/spec/insist/comparators_spec.rb0000664000000000000000000000465012537705054017672 0ustar rootrootrequire "spec_setup" require "insist" describe Insist::Comparators do subject do Insist.new { 30 } end describe "#==" do it "should be OK if the #value is equal" do subject == 30 end it "should fail if the #value is not equal" do insist { subject == 0 }.fails end end describe "#<=" do it "should be OK if the #value is less than or equal" do larger = subject.value + 1 subject <= larger end it "should be OK if the #value is equal" do subject >= subject.value end it "should fail if the #value is greater" do smaller = subject.value - 1 insist { subject <= smaller }.fails end end describe "#>=" do it "should be OK if the #value is greater than" do smaller = subject.value - 1 subject >= smaller end it "should be OK if the #value is equal" do subject >= subject.value end it "should fail if the #value is lesser" do larger = subject.value + 1 insist { subject >= larger }.fails end end describe "#<" do it "should be OK if the #value is less than" do larger = subject.value + 1 subject < larger end it "should fail if the #value is equal" do insist { subject < subject.value }.fails end it "should fail if the #value is greater" do smaller = subject.value - 1 insist { subject < smaller }.fails end end describe "#>" do it "should be OK if the #value is greater than" do smaller = subject.value - 1 subject > smaller end it "should fail if the #value is equal" do insist { subject > subject.value }.fails end it "should fail if the #value is lesser" do larger = subject.value + 1 insist { subject > larger }.fails end end describe "#=~", :if => (RUBY_VERSION >= "1.9.2") do subject do Insist.new { "hello" } end it "should be OK if the #value matches the given pattern" do subject =~ /hello/ end it "should fail if the #value does not match the pattern" do insist { subject =~ /world/ }.fails end end describe "#!~", :if => (RUBY_VERSION >= "1.9.2") do subject do Insist.new { "hello" } end it "should be OK if the #value does not match the pattern" do subject !~ /world/ end it "should fail if the #value matches the given pattern" do insist { subject !~ /hello/ }.fails end end end insist-1.0.0/spec/insist_spec.rb0000664000000000000000000000036212537705054015334 0ustar rootrootrequire "spec_setup" require "insist" describe Insist do subject do Insist.new { "Hello world" } end describe "#value" do it "should return the block value" do insist { subject.value } == "Hello world" end end end insist-1.0.0/spec/spec_setup.rb0000664000000000000000000000007512537705054015164 0ustar rootroot$: << File.join(File.dirname(File.dirname(__FILE__)), "lib") insist-1.0.0/lib/0000755000000000000000000000000012537705054012275 5ustar rootrootinsist-1.0.0/lib/insist.rb0000664000000000000000000000337612537705054014146 0ustar rootrootrequire "insist/namespace" require "insist/assert" require "insist/comparators" require "insist/enumerables" require "insist/failure" require "insist/nil" require "insist/predicates" require "insist/raises" # Insist on correctness. # # # Example: # # data = { "hello" => "world" } # insist { data["hello"] } == "world" # # This class aims to work similarly to how rspec's "should" stuff does, but # instead of molesting Object allows you to neatly wrap values with blocks # while still checking for expected values. class Insist class Failure < StandardError; end include Insist::Comparators include Insist::Enumerables include Insist::Nil include Insist::Assert include Insist::Raises include Insist::Predicates # Create a new insist with a block. # # Example: # # Insist.new { value } # # Better: # # insist { value } def initialize(&block) @callback = block end # def initialize def value # TODO(sissel): make caching the value optional @value ||= @callback.call return @value end # def value end # class Insist # Like Insist, but rejects (fails) on truthy values instead falsey ones. class Reject < Insist def assert(truthy, message) raise Insist::Failure.new(message) if truthy end # def assert end # class Reject module Kernel # A shortcut to 'Insist.new' # # Example: # # insist { "hello world" } != "fizzle" def insist(&block) return Insist.new(&block) end # def insist # A shortcut to 'Reject.new' # # Example: # # # This will fail (raises Insist::Failure) # reject { [1,2,3,4] }.include?(3) # # # This will succeed # reject { [1,2,3,4] }.include?(4) def reject(&block) return Reject.new(&block) end # def reject end # module Kernel insist-1.0.0/lib/insist/0000755000000000000000000000000012537705054013606 5ustar rootrootinsist-1.0.0/lib/insist/namespace.rb0000664000000000000000000000002212537705054016063 0ustar rootrootclass Insist; end insist-1.0.0/lib/insist/raises.rb0000664000000000000000000000057312537705054015430 0ustar rootroot module Insist::Raises # Assert raises def raises(exception_class) begin value rescue exception_class => e return # We're OK end assert(false, "Expected exception '#{exception_class}' but none was raised") end # def raises # Asserts a failure def fails raises(Insist::Failure) end # def fails end # module Insist::Raises insist-1.0.0/lib/insist/assert.rb0000664000000000000000000000042712537705054015441 0ustar rootroot module Insist::Assert # Assert something is true. # # This will raise Insist::Failure with the given message if the 'truthy' # value is false. def assert(truthy, message) raise Insist::Failure.new(message) if !truthy end # def assert end # module Insist::Assert insist-1.0.0/lib/insist/enumerables.rb0000664000000000000000000000042112537705054016434 0ustar rootroot # Provides assertions for enumerable-ish methods # # Example: # # insist { "foo" } == "foo" module Insist::Enumerables include Insist::Assert def include?(item) assert(value.include?(item), "Expected #{item.inspect} in #{value.inspect}") end end insist-1.0.0/lib/insist/failure.rb0000664000000000000000000000016412537705054015565 0ustar rootroot# A failure. This is raised if an `insist` check fails. class Insist::Failure < StandardError # Nothing here. end insist-1.0.0/lib/insist/comparators19.rb0000664000000000000000000000113012537705054016634 0ustar rootroot # TODO(sissel): This requires ruby 1.9.x module Insist::Comparators # value != expected def !=(expected) assert(value != expected, "Expected #{value.inspect} != #{expected.inspect}") end # def != # TODO(sissel): This requires ruby 1.9.x # value =~ pattern def =~(pattern) assert(value =~ pattern, "Expected #{value.inspect} =~ #{pattern.inspect}") end # def =~ # TODO(sissel): This requires ruby 1.9.x # value !~ pattern def !~(pattern) assert(value !~ pattern, "Expected #{value.inspect} !~ #{pattern.inspect}") end # def !~ end insist-1.0.0/lib/insist/comparators.rb0000664000000000000000000000172412537705054016473 0ustar rootroot # Provides the '==' assertion method. # # Example: # # insist { "foo" } == "foo" module Insist::Comparators include Insist::Assert require "insist/comparators19" if RUBY_VERSION >= "1.9.2" # value == expected def ==(expected) assert(value == expected, "Expected #{expected.inspect}, but got #{value.inspect}") end # def == # value <= expected def <=(expected) assert(value <= expected, "Expected #{value.inspect} <= #{expected.inspect}") end # def <= # value >= expected def >=(expected) assert(value >= expected, "Expected #{value.inspect} >= #{expected.inspect}") end # def >= # value > expected def >(expected) assert(value > expected, "Expected #{value.inspect} > #{expected.inspect}") end # def > # value < expected def <(expected) assert(value < expected, "Expected #{value.inspect} < #{expected.inspect}") end # def < end # module Insist::Comparators insist-1.0.0/lib/insist/nil.rb0000664000000000000000000000022712537705054014720 0ustar rootroot module Insist::Nil # Assert nil def nil? assert(value.nil?, "Expected nil, got #{@value.inspect}") end # def nil? end # module Insist::Nil insist-1.0.0/lib/insist/predicates.rb0000664000000000000000000000242612537705054016264 0ustar rootrootrequire "insist/namespace" require "insist/assert" module Insist::Predicates include Insist::Assert PREDICATE_METHOD_RE = /\?$/ # Fails if the value does not respond to a method. # # insist { "hurray" }.respond_to?(:size) def respond_to?(method) assert(value.respond_to?(method), "#{value.class} does not respond to the '#{method}' method") end # def respond_to? # Fails if the value.is_a?(klass) returns false. # # insist { "hurray" }.is_a?(Number) def is_a?(klass) assert(value.is_a?(klass), "#{value.class} is not a #{klass}") end # Pass through any 'foo?' style method calls to the 'value' # and fail if the the return is false. def method_missing(m, *args) # If this is a predicate method (ends in question mark) # call it on the value and assert truthiness. if PREDICATE_METHOD_RE.match(m.to_s) insist { value }.respond_to?(m) # call the method, like .empty?, result must be truthy. result = value.send(m, *args) assert(result, "#{value.class}{#{value.inspect}}##{m}(#{args.join(",")}) " \ "expected to return a truthy value, but returned #{result}") return result else return super(m, *args) end end # def method_missing end # module Insist::Predicates insist-1.0.0/notify-failure.sh0000664000000000000000000000027612537705054015027 0ustar rootroot#!/bin/sh "$@" status=$? if [ ! -z "$TMUX" ] ; then if [ "$status" -ne 0 ] ; then tmux display-message "Tests Fail" else tmux display-message "Tests OK" fi fi exit $status insist-1.0.0/.batcave/0000755000000000000000000000000012537705054013212 5ustar rootrootinsist-1.0.0/.batcave/manifest0000664000000000000000000000005312537705054014743 0ustar rootroot--- things: ruby: args: - insist insist-1.0.0/Gemfile.lock0000664000000000000000000000061212537705054013752 0ustar rootrootPATH remote: . specs: insist (0.0.5) GEM remote: http://rubygems.org/ specs: diff-lcs (1.1.3) rspec (2.8.0) rspec-core (~> 2.8.0) rspec-expectations (~> 2.8.0) rspec-mocks (~> 2.8.0) rspec-core (2.8.0) rspec-expectations (2.8.0) diff-lcs (~> 1.1.2) rspec-mocks (2.8.0) PLATFORMS java ruby DEPENDENCIES insist! rspec (~> 2.8.0) insist-1.0.0/README.md0000664000000000000000000000306112537705054013010 0ustar rootroot# insist { on readable assertions } I like rspec, but I don't like the '#should' junk. It scratches me the wrong way, I guess. I find this to be an unreadable mess: # yuck, if you ask me. somevalue.should eq(0) On the flip side, I really like the idea (make tests read like english). So instead of slapping '#should' on all objects and doing weird stuff like `expect { block }.to raise_error(thing)`, I just use blocks for everything in a kind of lazy-evaluation wrapping: # Check equality insist { value } == 30 # Insist an exception is raised insist { code }.raises(exception_class) Reads well, I think. ## Most minimal assertions possible Using rspec's 'subject' stuff, you can write tests that are perhaps even more minimal while still being clear. Here's an example test that fails. The subject is an 'insist' object, so you can just do the usual '==' and other methods on it: # spec/example_spec.rb describe "thing" do subject { insist { "whoa!" } } it "should be, like, awesome!" do subject == "awesome!" end end Running it: Failures: 1) thing should be, like, awesome! Failure/Error: subject == "awesome!" Insist::Failure: Expected "awesome!", but got "whoa!" # ./lib/insist/assert.rb:8:in `assert' # ./lib/insist/comparators.rb:12:in `==' # ./test.rb:5:in `block (2 levels) in ' Finished in 0.00208 seconds 1 example, 1 failure Failed examples: rspec ./test.rb:4 # thing should be, like, awesome! insist-1.0.0/insist.gemspec0000664000000000000000000000110512537705054014404 0ustar rootrootGem::Specification.new do |spec| files = %x{git ls-files}.split("\n") spec.name = "insist" spec.version = "1.0.0" spec.summary = "A simple block-driven assertion library for both testing and for production code" spec.description = spec.summary spec.license = "Apache 2" # Note: You should set the version explicitly. #spec.add_dependency "cabin", ">0" # for logging. apache 2 license spec.files = files spec.require_paths << "lib" spec.bindir = "bin" spec.authors = ["Jordan Sissel"] spec.email = ["jls@semicomplete.com"] #spec.homepage = "..." end insist-1.0.0/.gitignore0000664000000000000000000000002112537705054013512 0ustar rootroot.yardoc coverage insist-1.0.0/Gemfile0000664000000000000000000000011712537705054013023 0ustar rootrootsource :rubygems gemspec group :development do gem "rspec", "~> 2.8.0" end insist-1.0.0/Makefile0000664000000000000000000000165512537705054013200 0ustar rootrootGEMSPEC=$(shell ls *.gemspec) VERSION=$(shell awk -F\" '/spec.version/ { print $$2 }' $(GEMSPEC)) NAME=$(shell awk -F\" '/spec.name/ { print $$2 }' $(GEMSPEC)) GEM=$(NAME)-$(VERSION).gem .PHONY: test test: sh notify-failure.sh ruby test/all.rb .PHONY: testloop testloop: while true; do \ $(MAKE) test; \ $(MAKE) wait-for-changes; \ done .PHONY: serve-coverage serve-coverage: cd coverage; python -mSimpleHTTPServer .PHONY: wait-for-changes wait-for-changes: -inotifywait --exclude '\.swp' -e modify $$(find $(DIRS) -name '*.rb'; find $(DIRS) -type d) .PHONY: package package: | $(GEM) .PHONY: gem gem: $(GEM) $(GEM): gem build $(GEMSPEC) .PHONY: test-package test-package: $(GEM) # Sometimes 'gem build' makes a faulty gem. gem unpack $(GEM) rm -rf ftw-$(VERSION)/ .PHONY: publish publish: test-package gem push $(GEM) .PHONY: install install: $(GEM) gem install $(GEM) .PHONY: clean clean: -rm -rf .yardoc $(GEM) insist-1.0.0/LICENSE0000664000000000000000000000107612537705054012542 0ustar rootrootCopyright 2012-2013 Jordan Sissel and contributors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. insist-1.0.0/metadata.yml0000644000000000000000000000321312537705054014031 0ustar rootroot--- !ruby/object:Gem::Specification name: insist version: !ruby/object:Gem::Version version: 1.0.0 prerelease: platform: ruby authors: - Jordan Sissel autorequire: bindir: bin cert_chain: [] date: 2013-09-06 00:00:00.000000000 Z dependencies: [] description: A simple block-driven assertion library for both testing and for production code email: - jls@semicomplete.com executables: [] extensions: [] extra_rdoc_files: [] files: - .batcave/manifest - .gitignore - .travis.yml - Gemfile - Gemfile.lock - LICENSE - Makefile - README.md - insist.gemspec - lib/insist.rb - lib/insist/assert.rb - lib/insist/comparators.rb - lib/insist/comparators19.rb - lib/insist/enumerables.rb - lib/insist/failure.rb - lib/insist/namespace.rb - lib/insist/nil.rb - lib/insist/predicates.rb - lib/insist/raises.rb - notify-failure.sh - spec/insist/comparators_spec.rb - spec/insist/enumerables_spec.rb - spec/insist/nil_spec.rb - spec/insist/predicates_spec.rb - spec/insist/reject_spec.rb - spec/insist_spec.rb - spec/spec_setup.rb - test/all.rb - test/docs.rb - test/testing.rb homepage: licenses: - Apache 2 post_install_message: rdoc_options: [] require_paths: - lib - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 1.8.25 signing_key: specification_version: 3 summary: A simple block-driven assertion library for both testing and for production code test_files: [] insist-1.0.0/.travis.yml0000664000000000000000000000023112537705054013636 0ustar rootrootlanguage: ruby rvm: - 1.8.7 - 1.9.2 - 1.9.3 - jruby-18mode # JRuby in 1.9 mode - jruby-19mode # JRuby in 1.9 mode - rbx-18mode script: rspec insist-1.0.0/test/0000755000000000000000000000000012537705054012506 5ustar rootrootinsist-1.0.0/test/testing.rb0000664000000000000000000000054612537705054014517 0ustar rootrootrequire "rubygems" require "minitest/spec" # Add '../lib' to the require path. $: << File.join(File.dirname(__FILE__), "..", "lib") # I don't really like monkeypatching, but whatever, this is probably better # than overriding the 'describe' method. class MiniTest::Spec class << self # 'it' sounds wrong, call it 'test' alias :test :it end end insist-1.0.0/test/all.rb0000664000000000000000000000101512537705054013602 0ustar rootrootrequire "rubygems" require "minitest/spec" require "minitest/autorun" # Get coverage report require "simplecov" SimpleCov.start # Add '../lib' to the require path. $: << File.join(File.dirname(__FILE__), "..", "lib") def use(path) puts "Loading tests from #{path}" require File.expand_path(path) end dirname = File.dirname(__FILE__) use File.join(dirname, "docs.rb") # Load tests from ./*/**/*.rb (usually ./libraryname/....) glob = File.join(dirname, "*", "**", "*.rb") Dir.glob(glob).each do |path| use path end insist-1.0.0/test/docs.rb0000664000000000000000000000305312537705054013766 0ustar rootrootrequire "rubygems" require "yard" require File.join(File.expand_path(File.dirname(__FILE__)), "testing") describe "documentation tests" do before do # Use YARD to parse all ruby files found in '../lib' libdir = File.join(File.dirname(__FILE__), "..", "lib") YARD::Registry.load(Dir.glob(File.join(libdir, "**", "*.rb"))) @registry = YARD::Registry.all end test "All classes, methods, modules, and constants must be documented" do # YARD's parser works best in ruby 1.9.x, so skip 1.8.x skip if RUBY_VERSION < "1.9.2" # Note, the 'find the undocumented things' code here is # copied mostly from: YARD 0.7.5's lib/yard/cli/stats.rb # # Find all undocumented classes, modules, and constants undocumented = @registry.select do |o| [:class, :module, :constant].include?(o.type) && o.docstring.blank? end # Find all undocumented methods methods = @registry.select { |m| m.type == :method } methods.reject! { |m| m.is_alias? || !m.is_explicit? } undocumented += methods.select do |m| m.docstring.blank? && !m.overridden_method end if (undocumented.length > 0) message = ["The following are not documented"] undocumented.each do |o| message << "* #{o.type.to_s} #{o.to_s} <#{o.file}:#{o.line}>" end flunk(message.join("\n")) else pass end end end