Skip to content
This repository has been archived by the owner on Apr 13, 2020. It is now read-only.

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoriokusowski committed Apr 17, 2011
0 parents commit eabb69b
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--colour
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in samples_table.gemspec
gemspec
Empty file added README
Empty file.
2 changes: 2 additions & 0 deletions Rakefile
@@ -0,0 +1,2 @@
require 'bundler'
Bundler::GemHelper.install_tasks
30 changes: 30 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions lib/samples_table/version.rb
@@ -0,0 +1,3 @@
module SamplesTable
VERSION = "0.0.1"
end
24 changes: 24 additions & 0 deletions 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
31 changes: 31 additions & 0 deletions 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

0 comments on commit eabb69b

Please sign in to comment.