Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

lotsa tests

  • Loading branch information...
commit 1185cfc2d9057ef8d6f941caed6d98a5dd609625 1 parent 1cec954
@gfowley gfowley authored
View
3  .bundle/config
@@ -1 +1,2 @@
---- {}
+---
+BUNDLE_BIN: bin
View
2  .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
View
14 Gemfile.lock
@@ -1,14 +1,26 @@
PATH
remote: .
specs:
- iqeo-conf (0.0.1)
+ iqeo-conf (0.0.2)
GEM
remote: https://rubygems.org/
specs:
+ diff-lcs (1.1.3)
+ rake (0.9.2.2)
+ rspec (2.9.0)
+ rspec-core (~> 2.9.0)
+ rspec-expectations (~> 2.9.0)
+ rspec-mocks (~> 2.9.0)
+ rspec-core (2.9.0)
+ rspec-expectations (2.9.1)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.9.0)
PLATFORMS
ruby
DEPENDENCIES
iqeo-conf!
+ rake (~> 0.9.2)
+ rspec (~> 2.9.0)
View
7 Rakefile
@@ -6,4 +6,9 @@ Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/test*.rb']
t.verbose = true
-end
+end
+
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new('spec')
+
+task :default => :spec
View
16 bin/autospec
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+#
+# This file was generated by Bundler.
+#
+# The application 'autospec' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+require 'pathname'
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
+ Pathname.new(__FILE__).realpath)
+
+require 'rubygems'
+require 'bundler/setup'
+
+load Gem.bin_path('rspec-core', 'autospec')
View
16 bin/htmldiff
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+#
+# This file was generated by Bundler.
+#
+# The application 'htmldiff' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+require 'pathname'
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
+ Pathname.new(__FILE__).realpath)
+
+require 'rubygems'
+require 'bundler/setup'
+
+load Gem.bin_path('diff-lcs', 'htmldiff')
View
16 bin/ldiff
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+#
+# This file was generated by Bundler.
+#
+# The application 'ldiff' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+require 'pathname'
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
+ Pathname.new(__FILE__).realpath)
+
+require 'rubygems'
+require 'bundler/setup'
+
+load Gem.bin_path('diff-lcs', 'ldiff')
View
16 bin/rake
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+#
+# This file was generated by Bundler.
+#
+# The application 'rake' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+require 'pathname'
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
+ Pathname.new(__FILE__).realpath)
+
+require 'rubygems'
+require 'bundler/setup'
+
+load Gem.bin_path('rake', 'rake')
View
16 bin/rspec
@@ -0,0 +1,16 @@
+#!/usr/bin/env ruby
+#
+# This file was generated by Bundler.
+#
+# The application 'rspec' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+require 'pathname'
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
+ Pathname.new(__FILE__).realpath)
+
+require 'rubygems'
+require 'bundler/setup'
+
+load Gem.bin_path('rspec-core', 'rspec')
View
6 iqeo-conf.gemspec
@@ -9,8 +9,12 @@ Gem::Specification.new do |gem|
gem.homepage = "http://github.com/iqeo/iqeo-conf"
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.files = `git ls-files`.split("\n")
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ gem.test_files = `git ls-files -- {spec}/*`.split("\n")
gem.name = "iqeo-conf"
gem.require_paths = ["lib"]
gem.version = Iqeo::Configuration::VERSION
+
+ gem.add_development_dependency "rspec", "~> 2.9.0"
+ gem.add_development_dependency "rake", "~> 0.9.2"
+
end
View
22 lib/iqeo/configuration.rb
@@ -1,12 +1,20 @@
require_relative "configuration/version"
+# todo: access to items by hash
+# todo: indifferent hash access
+# todo: nested configurations
+# todo: inherited settings for nested configurations
+# todo: load configurations from string & file
+# todo: load other formats from string & file - YAML, XML?
+
module Iqeo
class Configuration
- # todo: tests - init without block, with block & param, with plain block
- # todo: instance_eval vs. yield (arity == 0) ?
+ def self.version
+ VERSION
+ end
def initialize &block
@items = {}
@@ -19,13 +27,11 @@ def initialize &block
end
end
- # todo: tests - with value, without value, multiple values ?, optional '=' with value ?
- # todo: why does '=' break for instance eval ? - is it actually setting a local variable ???
-
- def method_missing name, *value
+ def method_missing name, *values
name = name.to_s.chomp('=').to_sym
- return @items[name] if value.empty?
- @items[name] = value.first
+ return @items[name] if values.empty?
+ return @items[name] = values if values.size > 1
+ return @items[name] = values.first
end
end
View
204 spec/configuration_spec.rb
@@ -0,0 +1,204 @@
+require 'spec_helper'
+require 'iqeo/configuration'
+
+include Iqeo
+
+describe Configuration do
+
+ it 'should report the correct version' do
+ Configuration.version.should == Configuration::VERSION
+ end
+
+ context 'at creation' do
+
+ it 'should not require a block' do
+ Configuration.new.should be_a Configuration
+ end
+
+ it 'should accept a block with arity 0' do
+ Configuration.new { }.should be_a Configuration
+ end
+
+ it 'should instance eval block with arity 0' do
+ conf_eval = nil
+ conf_new = Configuration.new { conf_eval = self }
+ conf_new.should be conf_eval
+ end
+
+ it 'should accept a block with arity 1' do
+ Configuration.new { |arg| }.should be_a Configuration
+ end
+
+ it 'should yield self to block with arity 1' do
+ conf_yielded = nil
+ conf_new = Configuration.new { |conf| conf_yielded = conf }
+ conf_new.should be conf_yielded
+ end
+
+ end
+
+ context 'instance' do
+
+ it 'sets and retrieves simple values' do
+ conf = nil
+ expect do
+ conf = Configuration.new
+ conf.alpha 1
+ conf.bravo "two"
+ conf.charlie 3.0
+ conf.delta :four
+ end.to_not raise_error
+ conf.should_not be_nil
+ conf.alpha.should == 1 and conf.alpha.should be_a Fixnum
+ conf.bravo.should == "two" and conf.bravo.should be_a String
+ conf.charlie.should == 3.0 and conf.charlie.should be_a Float
+ conf.delta.should == :four and conf.delta.should be_a Symbol
+ end
+
+ it 'sets and retrieves complex values' do
+ conf = nil
+ expect do
+ conf = Configuration.new
+ conf.alpha = [ :a, :b, :c ]
+ conf.bravo = { :a => 1, :b => 2, :c => 3 }
+ end.to_not raise_error
+ conf.should_not be_nil
+ conf.alpha.should == [ :a, :b, :c] and conf.alpha.should be_an Array
+ conf.alpha.size.should == 3
+ conf.alpha[0].should == :a
+ conf.alpha[1].should == :b
+ conf.alpha[2].should == :c
+ conf.bravo.should == { :a => 1, :b => 2, :c => 3} and conf.bravo.should be_a Hash
+ conf.bravo.size.should == 3
+ conf.bravo[:a].should == 1
+ conf.bravo[:b].should == 2
+ conf.bravo[:c].should == 3
+ end
+
+ it 'returns nil when retrieving non-existent settings' do
+ conf = Configuration.new
+ conf.not_a_setting.should be_nil
+ end
+
+ it 'sets and retrieves multiple values as an array' do
+ conf = nil
+ expect do
+ conf = Configuration.new
+ conf.alpha :a, :b, :c
+ end.to_not raise_error
+ conf.should_not be_nil
+ conf.alpha.should == [ :a, :b, :c ] and conf.alpha.should be_an Array
+ end
+
+ end
+
+ context 'yield DSL' do
+
+ it 'accepts settings without =' do
+ conf = nil
+ expect do
+ conf = Configuration.new do |c|
+ c.alpha :value
+ end
+ end.to_not raise_error
+ conf.should_not be_nil
+ conf.alpha.should == :value
+ end
+
+ it 'accepts settings with =' do
+ conf = nil
+ expect do
+ conf = Configuration.new do |c|
+ c.alpha = :value
+ end
+ end.to_not raise_error
+ conf.should_not be_nil
+ conf.alpha.should == :value
+ end
+
+ it 'can refer to an existing setting' do
+ conf = nil
+ expect do
+ conf = Configuration.new do |c|
+ c.alpha = :value
+ c.bravo = c.alpha
+ c.charlie c.bravo
+ end
+ end.to_not raise_error
+ conf.should_not be_nil
+ conf.alpha.should == :value
+ conf.bravo.should == :value
+ conf.charlie.should == :value
+ end
+
+ it 'returns value when creating/changing a setting' do
+ conf = nil
+ expect do
+ conf = Configuration.new do |c|
+ c.bravo = c.alpha = :value
+ end
+ end.to_not raise_error
+ conf.alpha.should == :value
+ conf.bravo.should == :value
+ end
+
+ end
+
+ context 'eval DSL' do
+
+ it 'accepts settings without =' do
+ conf = nil
+ expect do
+ conf = Configuration.new do
+ alpha :value
+ end
+ end.to_not raise_error
+ conf.should_not be_nil
+ conf.alpha.should == :value
+ end
+
+ it 'set local variables with =' do
+ conf = alpha = nil
+ expect do
+ alpha = nil
+ conf = Configuration.new do
+ alpha = :value
+ bravo alpha
+ end
+ end.to_not raise_error
+ conf.should_not be_nil
+ conf.alpha.should be_nil
+ conf.bravo.should == :value
+ alpha.should == :value # local alpha set by matching variables
+ end
+
+ it 'can refer to an existing setting' do
+ conf = nil
+ expect do
+ conf = Configuration.new do |c|
+ c.alpha :value
+ c.bravo c.alpha
+ c.charlie c.bravo
+ end
+ end.to_not raise_error
+ conf.should_not be_nil
+ conf.alpha.should == :value
+ conf.bravo.should == :value
+ conf.charlie.should == :value
+ end
+
+ it 'returns value when creating/changing a setting' do
+ conf = nil
+ expect do
+ conf = Configuration.new do
+ bravo alpha :value
+ end
+ end.to_not raise_error
+ conf.alpha.should == :value
+ conf.bravo.should == :value
+ end
+
+ end
+
+
+end
View
11 spec/spec_helper.rb
@@ -0,0 +1,11 @@
+# This file was generated by the `rspec --init` command. Conventionally, all
+# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
+# Require this file using `require "spec_helper.rb"` to ensure that it is only
+# loaded once.
+#
+# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
+RSpec.configure do |config|
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.filter_run :focus
+end
Please sign in to comment.
Something went wrong with that request. Please try again.