From ce6cfb7977f0f6feeb57f8cd63560f332843333f Mon Sep 17 00:00:00 2001 From: Stormwind Date: Fri, 1 May 2015 12:43:01 +0200 Subject: [PATCH] Add tests for Rubella::Input::Base --- lib/rubella/input/base.rb | 10 ++++++++++ spec/unit/rubella/input/base/data_spec.rb | 11 +++++++++++ spec/unit/rubella/input/base/each_spec.rb | 16 ++++++++++++++++ spec/unit/rubella/input/base/new_spec.rb | 17 +++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 spec/unit/rubella/input/base/data_spec.rb create mode 100644 spec/unit/rubella/input/base/each_spec.rb create mode 100644 spec/unit/rubella/input/base/new_spec.rb diff --git a/lib/rubella/input/base.rb b/lib/rubella/input/base.rb index a59a2b6..7193e76 100644 --- a/lib/rubella/input/base.rb +++ b/lib/rubella/input/base.rb @@ -9,6 +9,16 @@ module Rubella class Base attr_reader :data + # Constructor + # Create a new Rubella::Input::Base object using the given data + # + # @param var Input data + # @return Rubell::Input::Base + # + def initialize data + @data = data + end + # Passes each dataset trought the given block. # # @param pointer to block diff --git a/spec/unit/rubella/input/base/data_spec.rb b/spec/unit/rubella/input/base/data_spec.rb new file mode 100644 index 0000000..4aa6afe --- /dev/null +++ b/spec/unit/rubella/input/base/data_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe Rubella::Input::Base, '.data' do + + it "retuns the stored data" do + input = Rubella::Input::Base.new [3, 4, 5] + + expect(input.data).to eq([3, 4, 5]) + end + +end \ No newline at end of file diff --git a/spec/unit/rubella/input/base/each_spec.rb b/spec/unit/rubella/input/base/each_spec.rb new file mode 100644 index 0000000..91b1a8c --- /dev/null +++ b/spec/unit/rubella/input/base/each_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe Rubella::Input::Base, '.each' do + + it "passes the data through the given block" do + storage = Rubella::Input::Base.new [3, 4, 5] + + sum = 0 + storage.each do |value| + sum = sum + value + end + + expect(sum).to eq(12) + end + +end \ No newline at end of file diff --git a/spec/unit/rubella/input/base/new_spec.rb b/spec/unit/rubella/input/base/new_spec.rb new file mode 100644 index 0000000..48a19f4 --- /dev/null +++ b/spec/unit/rubella/input/base/new_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +describe Rubella::Input::Base, '.new' do + + it "creates a new Input instance" do + input = Rubella::Input::Base.new nil + + expect(input).to be_instance_of(Rubella::Input::Base) + end + + it "uses the given data" do + input = Rubella::Input::Base.new 54 + + expect(input.data).to eq(54) + end + +end \ No newline at end of file