Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: master
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 4 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
2  Gemfile
@@ -1,6 +1,6 @@
source "http://rubygems.org"
-gem "activesupport", '~>2.3.5'
+gem "activesupport"
group :development do
gem "rspec", "~> 2.3.0"
View
14 Gemfile.lock
@@ -1,15 +1,19 @@
GEM
remote: http://rubygems.org/
specs:
- activesupport (2.3.10)
- diff-lcs (1.1.2)
+ activesupport (3.2.2)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ diff-lcs (1.1.3)
git (1.2.5)
+ i18n (0.6.0)
jeweler (1.5.2)
bundler (~> 1.0.0)
git (>= 1.2.5)
rake
- rake (0.8.7)
- rcov (0.9.9)
+ multi_json (1.1.0)
+ rake (0.9.2.2)
+ rcov (1.0.0)
rspec (2.3.0)
rspec-core (~> 2.3.0)
rspec-expectations (~> 2.3.0)
@@ -23,7 +27,7 @@ PLATFORMS
ruby
DEPENDENCIES
- activesupport (~> 2.3.5)
+ activesupport
bundler (~> 1.0.0)
jeweler (~> 1.5.2)
rcov
View
6 README.rdoc
@@ -128,6 +128,12 @@ The implicit rules are:
You can add extra rules with the rule method - see Masterplan::DefineRules#rule for details.
+You can control the verbosity of the output with the :format option:
+
+ >> Masterplan.compare(:scheme => doc, :to => {:example => :data}, :format => :mini)
+
+Valid values are :full (the default), or :mini. :mini produces only a one-line output (leaving out the "Expected...but was" part).
+
There is also an added assertion for unit tests or specs:
assert_masterplan(doc, [{:example => :data})
View
4 Rakefile
@@ -13,12 +13,12 @@ require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
gem.name = "masterplan"
- gem.homepage = "http://github.com/traveliq/masterplan"
+ gem.homepage = "http://github.com/MGPalmer/masterplan"
gem.license = "MIT"
summary = %Q{Masterplan is a library for comparing Ruby data structures against predefined templates - like XML Schema without the XML.}
gem.summary = summary
gem.description = summary + " Please see the README on github for more information."
- gem.email = "developer@traveliq.net"
+ gem.email = "mgpalmer@monogreen.de"
gem.authors = ["Martin Tepper"]
# Include your dependencies below. Runtime dependencies are required when using your gem,
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
View
26 lib/masterplan.rb
@@ -17,12 +17,14 @@ class FailedError < Test::Unit::AssertionFailedError
class << self
- def compare(options = {:scheme => {}, :to => {}})
+ def compare(options = {:scheme => {}, :to => {}, :format => :full})
scheme = options[:scheme]
testee = options[:to]
+ format = options[:format] || :full
raise ArgumentError, ":to needs to be a hash !" unless testee.is_a?(Hash)
raise ArgumentError, ":scheme needs to be a Masterplan::Document !" unless scheme.is_a?(Document)
- compare_hash(scheme, testee)
+ raise ArgumentError, ":format needs to be one of [:full, :mini] !" unless [:full, :mini].include?(format)
+ compare_hash(scheme, testee, format)
true
end
@@ -36,7 +38,7 @@ def compare_value(template, value, path)
end
end
- def compare_hash(template, testee, trail = ["root"])
+ def compare_hash(template, testee, format, trail = ["root"])
template.stringify_keys!
testee.stringify_keys!
raise FailedError, "keys don't match in #{format_path(trail)}:\nexpected:\t#{template.keys.sort.join(',')}\nreceived:\t#{testee.keys.sort.join(',')}" if template.keys.sort != testee.keys.sort
@@ -51,7 +53,7 @@ def compare_hash(template, testee, trail = ["root"])
array_path = current_path + [index]
compare_value(elements_template, elements_value, format_path(array_path))
if elements_value.is_a?(Hash)
- compare_hash(elements_template, elements_value, array_path)
+ compare_hash(elements_template, elements_value, format, array_path)
end
end
end
@@ -61,16 +63,16 @@ def compare_hash(template, testee, trail = ["root"])
array_path = current_path + [index]
compare_value(elements_template, elements_value, format_path(array_path))
if elements_value.is_a?(Hash)
- compare_hash(elements_template, elements_value, array_path)
+ compare_hash(elements_template, elements_value, format, array_path)
end
end
end
if value.is_a?(Hash)
if t_value.is_a?(Masterplan::Rule)
compare_value(t_value, value, current_path)
- compare_hash(t_value.example_value, value, current_path)
+ compare_hash(t_value.example_value, value, format, current_path)
else
- compare_hash(t_value, value, current_path)
+ compare_hash(t_value, value, format, current_path)
end
end
end
@@ -81,10 +83,14 @@ def compare_hash(template, testee, trail = ["root"])
error = Masterplan::FailedError.new
error.printed = true
- expected = PP.pp(template, '')
- outcome = PP.pp(testee, '')
+ if format == :mini
+ raise error, e.message, caller
+ else
+ expected = PP.pp(template, '')
+ outcome = PP.pp(testee, '')
- raise error, "#{e.message}\n\nExpected:\n#{expected}\n\nbut was:\n#{outcome}", caller
+ raise error, "#{e.message}\n\nExpected:\n#{expected}\n\nbut was:\n#{outcome}", caller
+ end
end
def format_path(trail)
View
2  lib/masterplan/define_rules.rb
@@ -5,7 +5,7 @@ module Masterplan
module DefineRules
# This turns the supplied +example_value+ (any object) into an object that carries rules about itself with it.
- # The rules will be applied when a template is compared with assert_masterplan. Rules are:
+ # The rules will be applied when a template is compared with assert_masterplan or Masterplan.compare. Rules are:
# (default): This always applies - the value must be of the same class as the +example_value+
# 'allow_nil': This allows the value to be nil (breaking the first rule)
# 'included_in': Pass an array of values - the value must be one of these
View
23 masterplan.gemspec
@@ -4,14 +4,14 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
- s.name = %q{masterplan}
- s.version = "0.3.1"
+ s.name = "masterplan"
+ s.version = "0.3.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Martin Tepper"]
- s.date = %q{2011-02-02}
- s.description = %q{Masterplan is a library for comparing Ruby data structures against predefined templates - like XML Schema without the XML. Please see the README on github for more information.}
- s.email = %q{developer@traveliq.net}
+ s.date = "2012-03-21"
+ s.description = "Masterplan is a library for comparing Ruby data structures against predefined templates - like XML Schema without the XML. Please see the README on github for more information."
+ s.email = "mgpalmer@monogreen.de"
s.extra_rdoc_files = [
"LICENSE.txt",
"README.rdoc"
@@ -34,35 +34,34 @@ Gem::Specification.new do |s|
"spec/masterplan_spec.rb",
"spec/spec_helper.rb"
]
- s.homepage = %q{http://github.com/traveliq/masterplan}
+ s.homepage = "http://github.com/MGPalmer/masterplan"
s.licenses = ["MIT"]
s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.7}
- s.summary = %q{Masterplan is a library for comparing Ruby data structures against predefined templates - like XML Schema without the XML.}
+ s.rubygems_version = "1.8.19"
+ s.summary = "Masterplan is a library for comparing Ruby data structures against predefined templates - like XML Schema without the XML."
s.test_files = [
"spec/masterplan_spec.rb",
"spec/spec_helper.rb"
]
if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<activesupport>, ["~> 2.3.5"])
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
s.add_development_dependency(%q<rcov>, [">= 0"])
else
- s.add_dependency(%q<activesupport>, ["~> 2.3.5"])
+ s.add_dependency(%q<activesupport>, [">= 0"])
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
s.add_dependency(%q<rcov>, [">= 0"])
end
else
- s.add_dependency(%q<activesupport>, ["~> 2.3.5"])
+ s.add_dependency(%q<activesupport>, [">= 0"])
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
View
57 spec/masterplan_spec.rb
@@ -67,6 +67,16 @@ def test_value_and_expect(testee, *error_and_descripton)
end.should raise_error(ArgumentError, /scheme needs to be a Masterplan::Document/)
end
+ it "complains if not given a proper format key" do
+ lambda do
+ Masterplan.compare(
+ :scheme => Masterplan::Document.new({}),
+ :to => {},
+ :format => :medium
+ )
+ end.should raise_error(ArgumentError, ":format needs to be one of [:full, :mini] !")
+ end
+
it "complains if there are extra keys" do
test_value_and_expect(
{ :ship => {}, :boat => {} },
@@ -109,11 +119,56 @@ def test_value_and_expect(testee, *error_and_descripton)
)
end
+ [nil, :full].each do |format|
+ it "produces full output for format = #{format}" do
+ lambda do
+ Masterplan.compare(
+ :scheme => @scheme,
+ :to => { :ship => [] },
+ :format => format
+ )
+ end.should raise_error(
+ /value at 'root'=>'ship' \(Array\) is not a Hash !\n\s*?Expected:.*?but was/m
+ )
+ end
+ end
+
+ it "produces one-line output when using :mini format" do
+ lambda do
+ Masterplan.compare(
+ :scheme => @scheme,
+ :to => { :ship => [] },
+ :format => :mini
+ )
+ end.should raise_error(
+ "value at 'root'=>'ship' (Array) is not a Hash !"
+ )
+ end
+
it "checks all values of value arrays, but only against the first array value of the scheme"
it "checks all array values one-to-one if the compare_each rule is used"
end
- it "convertsinto plain example hashes"
+ it "converts into plain example hashes" do
+ @scheme.to_hash.should == {
+ "ship" => {
+ "parts" => [
+ {
+ "name" => "Mast",
+ "scream" => "AAAAAAH",
+ "length" => 12.3,
+ "material" => "wood"
+ },
+ {
+ "name" => "Rudder",
+ "scream" => "HAAAAAARGH",
+ "length" => nil,
+ "material" => "steel"
+ }
+ ]
+ }
+ }
+ end
it "doesn't create a Document out of anything other than a Hash"
it "checks that the examples of rules obey the rules"
it "has a unit test extension method"

No commit comments for this range

Something went wrong with that request. Please try again.