Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit d4b055dce1ac0cb6baeee0ed264c8079acc85500 @jm committed Oct 6, 2008
Showing with 5,479 additions and 0 deletions.
  1. +4 −0 History.txt
  2. +20 −0 License.txt
  3. +22 −0 Manifest.txt
  4. +7 −0 PostInstall.txt
  5. +68 −0 README.rdoc
  6. +4 −0 Rakefile
  7. +73 −0 config/hoe.rb
  8. +15 −0 config/requirements.rb
  9. +16 −0 lib/matchy.rb
  10. +51 −0 lib/matchy/built_in/enumerable_expectations.rb
  11. +54 −0 lib/matchy/built_in/error_expectations.rb
  12. +82 −0 lib/matchy/built_in/operator_expectations.rb
  13. +125 −0 lib/matchy/built_in/truth_expectations.rb
  14. +44 −0 lib/matchy/expectation.rb
  15. +46 −0 lib/matchy/modals.rb
  16. +9 −0 lib/matchy/version.rb
  17. +46 −0 matchy.gemspec
  18. BIN pkg/matchy-0.0.1.gem
  19. BIN pkg/matchy-0.0.1.tgz
  20. +4 −0 pkg/matchy-0.0.1/History.txt
  21. +20 −0 pkg/matchy-0.0.1/License.txt
  22. +22 −0 pkg/matchy-0.0.1/Manifest.txt
  23. +7 −0 pkg/matchy-0.0.1/PostInstall.txt
  24. +68 −0 pkg/matchy-0.0.1/README.rdoc
  25. +4 −0 pkg/matchy-0.0.1/Rakefile
  26. +73 −0 pkg/matchy-0.0.1/config/hoe.rb
  27. +15 −0 pkg/matchy-0.0.1/config/requirements.rb
  28. +16 −0 pkg/matchy-0.0.1/lib/matchy.rb
  29. +51 −0 pkg/matchy-0.0.1/lib/matchy/built_in/enumerable_expectations.rb
  30. +54 −0 pkg/matchy-0.0.1/lib/matchy/built_in/error_expectations.rb
  31. +82 −0 pkg/matchy-0.0.1/lib/matchy/built_in/operator_expectations.rb
  32. +125 −0 pkg/matchy-0.0.1/lib/matchy/built_in/truth_expectations.rb
  33. +44 −0 pkg/matchy-0.0.1/lib/matchy/expectation.rb
  34. +46 −0 pkg/matchy-0.0.1/lib/matchy/modals.rb
  35. +9 −0 pkg/matchy-0.0.1/lib/matchy/version.rb
  36. +46 −0 pkg/matchy-0.0.1/matchy.gemspec
  37. +1,585 −0 pkg/matchy-0.0.1/setup.rb
  38. +65 −0 pkg/matchy-0.0.1/test/test_enumerable_expectations.rb
  39. +67 −0 pkg/matchy-0.0.1/test/test_error_expectations.rb
  40. +31 −0 pkg/matchy-0.0.1/test/test_expectation_base.rb
  41. +2 −0 pkg/matchy-0.0.1/test/test_helper.rb
  42. +27 −0 pkg/matchy-0.0.1/test/test_modals.rb
  43. +137 −0 pkg/matchy-0.0.1/test/test_operator_expectations.rb
  44. +119 −0 pkg/matchy-0.0.1/test/test_truth_expectations.rb
  45. +1,585 −0 setup.rb
  46. +34 −0 tasks/deployment.rake
  47. +7 −0 tasks/environment.rake
  48. +65 −0 test/test_enumerable_expectations.rb
  49. +67 −0 test/test_error_expectations.rb
  50. +31 −0 test/test_expectation_base.rb
  51. +2 −0 test/test_helper.rb
  52. +27 −0 test/test_modals.rb
  53. +137 −0 test/test_operator_expectations.rb
  54. +119 −0 test/test_truth_expectations.rb
@@ -0,0 +1,4 @@
+== 0.0.1 2008-10-03
+
+* 1 major enhancement:
+ * Initial release
@@ -0,0 +1,20 @@
+Copyright (c) 2008 Jeremy McAnally
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
+History.txt
+Manifest.txt
+README.rdoc
+Rakefile
+matchy.gemspec
+History.txt
+License.txt
+Manifest.txt
+PostInstall.txt
+README.rdoc
+Rakefile
+config/hoe.rb
+config/requirements.rb
+lib/matchy.rb
+lib/matchy/version.rb
+lib/matchy/expectation.rb
+lib/matchy/modals.rb
+lib/matchy/built_in/enumerable_expectations.rb
+lib/matchy/built_in/error_expectations.rb
+lib/matchy/built_in/operator_expectations.rb
+lib/matchy/built_in/truth_expectations.rb
+setup.rb
@@ -0,0 +1,7 @@
+
+For more information on matchy, see http://matchy.rubyforge.org
+
+NOTE: Change this information in PostInstall.txt
+You can also delete it if you don't want it.
+
+
@@ -0,0 +1,68 @@
+= matchy
+
+* http://github.com/jeremymcanally/matchy
+
+== DESCRIPTION:
+
+Hate writing assertions? Need a little behavior-driven love in your tests? Then matchy is for you.
+
+== FEATURES/PROBLEMS:
+
+* Get the beauty of RSpec without all the overhead
+* Create your own matchers (coming soon)
+
+== SYNOPSIS:
+
+* Get BDD on your objects
+
+ x = 13 * 4
+ x.should == 42
+
+ y = "hello"
+ y.length.should_not be(4)
+
+* Use familiar syntax to specify things
+
+ # RSpec
+ "my string".should =~ /string/
+ lambda { raise "FAIL" }.should raise_error
+
+ # matchy
+ "my string".should =~ /string/
+ lambda { raise "FAIL" }.should raise_error
+
+* Get the speed of Test:Unit with the syntax of RSpec
+
+== REQUIREMENTS:
+
+* Test::Unit (you got it)
+
+== INSTALL:
+
+ $ gem sources -a http://gems.github.com
+ $ sudo gem install jeremymcanally-context
+
+== LICENSE:
+
+(The MIT License)
+
+Copyright (c) 2008 Jeremy McAnally
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
+require 'config/requirements'
+require 'config/hoe' # setup Hoe + all gem configuration
+
+Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,73 @@
+require 'matchy/version'
+
+AUTHOR = 'Jeremy McAnally' # can also be an array of Authors
+EMAIL = "jeremy@entp.com"
+DESCRIPTION = "description of gem"
+GEM_NAME = 'matchy' # what ppl will type to install your gem
+RUBYFORGE_PROJECT = 'matchy' # The unix name for your project
+HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
+DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
+EXTRA_DEPENDENCIES = [
+# ['activesupport', '>= 1.3.1']
+] # An array of rubygem dependencies [name, version]
+
+@config_file = "~/.rubyforge/user-config.yml"
+@config = nil
+RUBYFORGE_USERNAME = "unknown"
+def rubyforge_username
+ unless @config
+ begin
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
+ rescue
+ puts <<-EOS
+ERROR: No rubyforge config file found: #{@config_file}
+Run 'rubyforge setup' to prepare your env for access to Rubyforge
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
+ EOS
+ exit
+ end
+ end
+ RUBYFORGE_USERNAME.replace @config["username"]
+end
+
+
+REV = nil
+# UNCOMMENT IF REQUIRED:
+# REV = YAML.load(`svn info`)['Revision']
+VERS = Matchy::VERSION::STRING + (REV ? ".#{REV}" : "")
+RDOC_OPTS = ['--quiet', '--title', 'matchy documentation',
+ "--opname", "index.html",
+ "--line-numbers",
+ "--main", "README",
+ "--inline-source"]
+
+class Hoe
+ def extra_deps
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
+ @extra_deps
+ end
+end
+
+# Generate all the Rake tasks
+# Run 'rake -T' to see list of generated tasks (from gem root directory)
+$hoe = Hoe.new(GEM_NAME, VERS) do |p|
+ p.developer(AUTHOR, EMAIL)
+ p.description = DESCRIPTION
+ p.summary = DESCRIPTION
+ p.url = HOMEPATH
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
+ p.test_globs = ["test/**/test_*.rb"]
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
+
+ # == Optional
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
+ #p.extra_deps = EXTRA_DEPENDENCIES
+
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
+ end
+
+CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
+PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
+$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
+$hoe.rsync_args = '-av --delete --ignore-errors'
+$hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,15 @@
+require 'fileutils'
+include FileUtils
+
+require 'rubygems'
+%w[rake hoe newgem rubigen].each do |req_gem|
+ begin
+ require req_gem
+ rescue LoadError
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
+ puts "Installation: gem install #{req_gem} -y"
+ exit
+ end
+end
+
+$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -0,0 +1,16 @@
+$:.unshift(File.dirname(__FILE__)) unless
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
+
+require 'rubygems'
+require 'test/unit'
+
+require 'matchy/expectation'
+require 'matchy/modals'
+require 'matchy/version'
+
+require 'matchy/built_in/enumerable_expectations'
+require 'matchy/built_in/error_expectations'
+require 'matchy/built_in/truth_expectations'
+require 'matchy/built_in/operator_expectations'
+
+Test::Unit::TestCase.send(:include, Matchy::Expectations::TestCaseExtensions)
@@ -0,0 +1,51 @@
+module Matchy
+ module Expectations
+ class IncludeExpectation < Base
+ def matches?(obj)
+ @object.each do |o|
+ return false unless obj.include?(o)
+ end
+
+ true
+ end
+ end
+
+ class ExcludeExpectation < Base
+ def matches?(obj)
+ @object.each do |o|
+ return false unless !obj.include?(o)
+ end
+
+ true
+ end
+ end
+
+ module TestCaseExtensions
+ # Calls +include?+ on the receiver for any object. You can also provide
+ # multiple arguments to see if all of them are included.
+ #
+ # ==== Examples
+ #
+ # [1,2,3].should include(1)
+ # [7,8,8].should_not include(3)
+ # ['a', 'b', 'c'].should include('a', 'c')
+ #
+ def include(*obj)
+ Matchy::Expectations::IncludeExpectation.new(obj, self)
+ end
+
+ # Expects the receiver to exclude the given object(s). You can provide
+ # multiple arguments to see if all of them are included.
+ #
+ # ==== Examples
+ #
+ # [1,2,3].should exclude(16)
+ # [7,8,8].should_not exclude(7)
+ # ['a', 'b', 'c'].should exclude('e', 'f', 'g')
+ #
+ def exclude(*obj)
+ Matchy::Expectations::ExcludeExpectation.new(obj, self)
+ end
+ end
+ end
+end
@@ -0,0 +1,54 @@
+module Matchy
+ module Expectations
+ class RaiseErrorExpectation < Base
+ def matches?(obj)
+ begin
+ obj.call
+ return false
+ rescue StandardError => e
+ return false unless e.class.ancestors.include?(@object)
+
+ return true
+ end
+ end
+ end
+
+ class ThrowSymbolExpectation < Base
+ def matches?(obj)
+ begin
+ obj.call
+ rescue NameError => e
+ raise e unless e.message =~ /uncaught throw/
+ thrown_symbol = e.name.to_sym
+ ensure
+ return @object == thrown_symbol
+ end
+ end
+ end
+
+ module TestCaseExtensions
+ # Expects a lambda to raise an error. You can specify the error or leave it blank to encompass
+ # any error.
+ #
+ # ==== Examples
+ #
+ # lambda { raise "FAILURE." }.should raise_error
+ # lambda { puts i_dont_exist }.should raise_error(NameError)
+ #
+ def raise_error(obj = StandardError)
+ Matchy::Expectations::RaiseErrorExpectation.new(obj, self)
+ end
+
+ # Expects a lambda to throw an error.
+ #
+ # ==== Examples
+ #
+ # lambda { throw :thing }.should throw_symbol(:thing)
+ # lambda { "not this time" }.should_not throw_symbol(:hello)
+ #
+ def throw_symbol(obj)
+ Matchy::Expectations::ThrowSymbolExpectation.new(obj, self)
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit d4b055d

Please sign in to comment.