Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jm committed Oct 6, 2008
0 parents commit d4b055d
Show file tree
Hide file tree
Showing 54 changed files with 5,479 additions and 0 deletions.
4 changes: 4 additions & 0 deletions History.txt
@@ -0,0 +1,4 @@
== 0.0.1 2008-10-03

* 1 major enhancement:
* Initial release
20 changes: 20 additions & 0 deletions License.txt
@@ -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.
22 changes: 22 additions & 0 deletions Manifest.txt
@@ -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
7 changes: 7 additions & 0 deletions PostInstall.txt
@@ -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.


68 changes: 68 additions & 0 deletions README.rdoc
@@ -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.
4 changes: 4 additions & 0 deletions Rakefile
@@ -0,0 +1,4 @@
require 'config/requirements'
require 'config/hoe' # setup Hoe + all gem configuration

Dir['tasks/**/*.rake'].each { |rake| load rake }
73 changes: 73 additions & 0 deletions config/hoe.rb
@@ -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 ""
15 changes: 15 additions & 0 deletions config/requirements.rb
@@ -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]))
16 changes: 16 additions & 0 deletions lib/matchy.rb
@@ -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)
51 changes: 51 additions & 0 deletions lib/matchy/built_in/enumerable_expectations.rb
@@ -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
54 changes: 54 additions & 0 deletions lib/matchy/built_in/error_expectations.rb
@@ -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

0 comments on commit d4b055d

Please sign in to comment.