Module: SamplesTable

Defined in:
lib/samples_table.rb,
lib/samples_table/version.rb

Overview

samples_table is a gem that helps the writing of spec cases. Based on cucumber’s tables, it can be used without dependencies.

How to configure(with RSpec): # spec_helper.rb RSpec.configure do |config|

#your old config here
config.extend SamplesTable, :type => :model

end

How to use: require ‘spec_helper’ describe Sale do

describe "selling fruits" do
  (samples [ :fruit , :quantity , :total ],
           [ :apple ,     1     ,   1.0  ],
           [ :apple ,     2     ,   2.0  ],
           [ :apple ,    10     ,   9.5  ],#should apply discount when sells 10+
           [ :orange,     1     ,   2.0  ],
           [ :orange,     2     ,   4.0  ],
           [ :orange,    10     ,  19.0  ]).each_sample do |sample|
    describe "when selling #{sample.fruit}" do
      before{subject.fruit = sample.fruit}
      describe "and the customer wants to buy #{sample.quantity}" do
        before{subject.quantity = sample.quantity}
        it "should totalize #{sample.total} bucks" do
          subject.total.should eql sample.total
        end
      end
    end
  end
end

end

Defined Under Namespace

Classes: Sample, Table

Constant Summary collapse

VERSION =
"0.0.2"

Instance Method Summary collapse

Instance Method Details

#samples(*args) ⇒ Object



58
59
60
# File 'lib/samples_table.rb', line 58

def samples(*args)
  Table.new(*args)
end