From eabb69bd66686341de35222cfaf1056eb5c81708 Mon Sep 17 00:00:00 2001 From: Gregorio Kusowski Date: Sun, 17 Apr 2011 16:22:47 -0300 Subject: [PATCH] First commit --- .gitignore | 4 ++++ .rspec | 1 + Gemfile | 4 ++++ README | 0 Rakefile | 2 ++ lib/samples_table.rb | 30 ++++++++++++++++++++++++++++++ lib/samples_table/version.rb | 3 +++ samples_table.gemspec | 24 ++++++++++++++++++++++++ spec/samples_table_spec.rb | 31 +++++++++++++++++++++++++++++++ 9 files changed, 99 insertions(+) create mode 100644 .gitignore create mode 100644 .rspec create mode 100644 Gemfile create mode 100644 README create mode 100644 Rakefile create mode 100644 lib/samples_table.rb create mode 100644 lib/samples_table/version.rb create mode 100644 samples_table.gemspec create mode 100644 spec/samples_table_spec.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4040c6c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.gem +.bundle +Gemfile.lock +pkg/* diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..53607ea --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--colour diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..157aa03 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "http://rubygems.org" + +# Specify your gem's dependencies in samples_table.gemspec +gemspec diff --git a/README b/README new file mode 100644 index 0000000..e69de29 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..14cfe0b --- /dev/null +++ b/Rakefile @@ -0,0 +1,2 @@ +require 'bundler' +Bundler::GemHelper.install_tasks diff --git a/lib/samples_table.rb b/lib/samples_table.rb new file mode 100644 index 0000000..c6b325f --- /dev/null +++ b/lib/samples_table.rb @@ -0,0 +1,30 @@ +module SamplesTable + class Table < Array + alias :each_sample :each + + def initialize(*values) + @header = values.shift + values.each do |sample_values| + self.<< sample_values + end + end + + def <<(sample_values) + super(Sample.new(@header, sample_values)) + end + + end + + class Sample + def initialize(keys, sample_values) + @sample_properties = Hash.new + keys.each do |key| + @sample_properties[key] = sample_values.shift + end + end + def method_missing(m, *args, &block) + @sample_properties[m] + end + end + +end diff --git a/lib/samples_table/version.rb b/lib/samples_table/version.rb new file mode 100644 index 0000000..e8c98b2 --- /dev/null +++ b/lib/samples_table/version.rb @@ -0,0 +1,3 @@ +module SamplesTable + VERSION = "0.0.1" +end diff --git a/samples_table.gemspec b/samples_table.gemspec new file mode 100644 index 0000000..284c630 --- /dev/null +++ b/samples_table.gemspec @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "samples_table/version" + +Gem::Specification.new do |s| + s.name = "samples_table" + s.version = SamplesTable::VERSION + s.platform = Gem::Platform::RUBY + + s.authors = ["Gregório Chalinski Kusowski"] + s.email = ["gregorio.kusowski@gmail.com"] + s.homepage = "http://github.com/gregoriokusowski" + s.summary = %q{Helper to create examples table for testing} + s.description = %q{Simple Table is a gem that enables the developer to create some examples in a table, making the job of writing specs easier} + + s.add_development_dependency 'rspec' + + s.rubyforge_project = "samples_table" + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.require_paths = ["lib"] +end diff --git a/spec/samples_table_spec.rb b/spec/samples_table_spec.rb new file mode 100644 index 0000000..6f865fa --- /dev/null +++ b/spec/samples_table_spec.rb @@ -0,0 +1,31 @@ +require 'rspec' +require 'samples_table' + +describe SamplesTable do + + subject do + SamplesTable::Table.new [:valor_teste , :nenhum_valor , :algo_legal , :esqueceram_de_mim ], + [ 66 , 10 , 20 , 66 ], + [ 15 , 30 , 20 , 30 ] + end + + let(:first_sample){subject[0]} + let(:second_sample){subject[1]} + + it {first_sample.valor_teste.should eql 66} + it {first_sample.nenhum_valor.should eql 10} + it {first_sample.algo_legal.should eql 20} + it {first_sample.esqueceram_de_mim.should eql 66} + + it {second_sample.valor_teste.should eql 15} + it {second_sample.nenhum_valor.should eql 30} + it {second_sample.algo_legal.should eql 20} + it {second_sample.esqueceram_de_mim.should eql 30} + + it {subject.size.should eql 2} + + it {subject.should be_a_kind_of(Array)} + + it {subject.should respond_to(:each_sample)} + +end \ No newline at end of file