samples_table 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/README.md +54 -0
- data/Rakefile +2 -0
- data/lib/samples_table.rb +90 -0
- data/lib/samples_table/version.rb +3 -0
- data/samples_table.gemspec +19 -0
- data/spec/samples_table_spec.rb +31 -0
- metadata +64 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
samples_table is a gem that helps the job of writing tests and specs.
|
2
|
+
Based on cucumber's tables, you can create simple test cases easily.
|
3
|
+
Since it 'embed' the table into ruby code, it avoids the need of configurations, and/or the creation and use of third test files for the examples.
|
4
|
+
|
5
|
+
***
|
6
|
+
### Default Configuration:
|
7
|
+
|
8
|
+
# Gemfile (you may just need to add the samples table line)
|
9
|
+
group :development, :test do
|
10
|
+
gem 'samples_table'
|
11
|
+
end
|
12
|
+
|
13
|
+
***
|
14
|
+
### Configuration(with RSpec):
|
15
|
+
|
16
|
+
# spec_helper.rb
|
17
|
+
RSpec.configure do |config|
|
18
|
+
#your old config here
|
19
|
+
config.extend SamplesTable, :type => :model
|
20
|
+
end
|
21
|
+
|
22
|
+
***
|
23
|
+
### Example(with RSpec):
|
24
|
+
|
25
|
+
#sale_spec.rb
|
26
|
+
require 'spec_helper'
|
27
|
+
describe Sale do
|
28
|
+
describe "selling fruits" do
|
29
|
+
(samples [ :fruit , :quantity , :total ],
|
30
|
+
[ :apple , 1 , 1.0 ],
|
31
|
+
[ :apple , 2 , 2.0 ],
|
32
|
+
[ :apple , 10 , 9.5 ],#should apply discount when sells 10+
|
33
|
+
[ :orange, 1 , 2.0 ],
|
34
|
+
[ :orange, 2 , 4.0 ],
|
35
|
+
[ :orange, 10 , 19.0 ]).each_sample do |sample|
|
36
|
+
describe "when selling #{sample.fruit}" do
|
37
|
+
before{subject.fruit = sample.fruit}
|
38
|
+
describe "and the customer wants to buy #{sample.quantity}" do
|
39
|
+
before{subject.quantity = sample.quantity}
|
40
|
+
it "should totalize #{sample.total} bucks" do
|
41
|
+
subject.total.should eql sample.total
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
***
|
50
|
+
Feel free to comment/help.
|
51
|
+
|
52
|
+
***
|
53
|
+
### License:
|
54
|
+
__samples_table__ is released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Copyright (c) 2011 Gregório Chalinski Kusowski
|
2
|
+
# https://github.com/gregoriokusowski/samples_table
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
|
22
|
+
# samples_table is a gem that helps the writing of spec cases.
|
23
|
+
# Based on cucumber's tables, it can be used without dependencies.
|
24
|
+
#
|
25
|
+
# How to configure(with RSpec):
|
26
|
+
# # spec_helper.rb
|
27
|
+
# RSpec.configure do |config|
|
28
|
+
# #your old config here
|
29
|
+
# config.extend SamplesTable, :type => :model
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# How to use:
|
33
|
+
# require 'spec_helper'
|
34
|
+
# describe Sale do
|
35
|
+
# describe "selling fruits" do
|
36
|
+
# (samples [ :fruit , :quantity , :total ],
|
37
|
+
# [ :apple , 1 , 1.0 ],
|
38
|
+
# [ :apple , 2 , 2.0 ],
|
39
|
+
# [ :apple , 10 , 9.5 ],#should apply discount when sells 10+
|
40
|
+
# [ :orange, 1 , 2.0 ],
|
41
|
+
# [ :orange, 2 , 4.0 ],
|
42
|
+
# [ :orange, 10 , 19.0 ]).each_sample do |sample|
|
43
|
+
# describe "when selling #{sample.fruit}" do
|
44
|
+
# before{subject.fruit = sample.fruit}
|
45
|
+
# describe "and the customer wants to buy #{sample.quantity}" do
|
46
|
+
# before{subject.quantity = sample.quantity}
|
47
|
+
# it "should totalize #{sample.total} bucks" do
|
48
|
+
# subject.total.should eql sample.total
|
49
|
+
# end
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
# end
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
module SamplesTable
|
57
|
+
|
58
|
+
def samples(*args)
|
59
|
+
Table.new(*args)
|
60
|
+
end
|
61
|
+
|
62
|
+
class Table < Array
|
63
|
+
alias :each_sample :each
|
64
|
+
|
65
|
+
def initialize(*values)
|
66
|
+
@header = values.shift
|
67
|
+
values.each do |sample_values|
|
68
|
+
self.<< sample_values
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def <<(sample_values)
|
73
|
+
super(Sample.new(@header, sample_values))
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
class Sample
|
79
|
+
def initialize(keys, sample_values)
|
80
|
+
@sample_properties = Hash.new
|
81
|
+
keys.each do |key|
|
82
|
+
@sample_properties[key] = sample_values.shift
|
83
|
+
end
|
84
|
+
end
|
85
|
+
def method_missing(m, *args, &block)
|
86
|
+
@sample_properties[m]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "samples_table/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "samples_table"
|
7
|
+
s.version = SamplesTable::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Gregório Chalinski Kusowski']
|
10
|
+
s.email = "gregorio.kusowski@gmail.com"
|
11
|
+
s.homepage = "https://github.com/gregoriokusowski/samples_table"
|
12
|
+
s.summary = "Helper to create examples table for testing"
|
13
|
+
s.description = "Simple Table is a gem that enables the developer to create some examples in a table, making the job of writing specs easier"
|
14
|
+
s.rubyforge_project = "samples_table"
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'samples_table'
|
3
|
+
|
4
|
+
describe SamplesTable do
|
5
|
+
|
6
|
+
subject do
|
7
|
+
SamplesTable::Table.new [:valor_teste , :nenhum_valor , :algo_legal , :esqueceram_de_mim ],
|
8
|
+
[ 66 , 10 , 20 , 66 ],
|
9
|
+
[ 15 , 30 , 20 , 30 ]
|
10
|
+
end
|
11
|
+
|
12
|
+
let(:first_sample){subject[0]}
|
13
|
+
let(:second_sample){subject[1]}
|
14
|
+
|
15
|
+
it {first_sample.valor_teste.should eql 66}
|
16
|
+
it {first_sample.nenhum_valor.should eql 10}
|
17
|
+
it {first_sample.algo_legal.should eql 20}
|
18
|
+
it {first_sample.esqueceram_de_mim.should eql 66}
|
19
|
+
|
20
|
+
it {second_sample.valor_teste.should eql 15}
|
21
|
+
it {second_sample.nenhum_valor.should eql 30}
|
22
|
+
it {second_sample.algo_legal.should eql 20}
|
23
|
+
it {second_sample.esqueceram_de_mim.should eql 30}
|
24
|
+
|
25
|
+
it {subject.size.should eql 2}
|
26
|
+
|
27
|
+
it {subject.should be_a_kind_of(Array)}
|
28
|
+
|
29
|
+
it {subject.should respond_to(:each_sample)}
|
30
|
+
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: samples_table
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- "Greg\xC3\xB3rio Chalinski Kusowski"
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-13 00:00:00 -03:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Simple Table is a gem that enables the developer to create some examples in a table, making the job of writing specs easier
|
18
|
+
email: gregorio.kusowski@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files: []
|
24
|
+
|
25
|
+
files:
|
26
|
+
- .gitignore
|
27
|
+
- .rspec
|
28
|
+
- Gemfile
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- lib/samples_table.rb
|
32
|
+
- lib/samples_table/version.rb
|
33
|
+
- samples_table.gemspec
|
34
|
+
- spec/samples_table_spec.rb
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: https://github.com/gregoriokusowski/samples_table
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project: samples_table
|
59
|
+
rubygems_version: 1.6.2
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Helper to create examples table for testing
|
63
|
+
test_files:
|
64
|
+
- spec/samples_table_spec.rb
|