0
0
Fork 0

Add tests for Rubella::Input::JSON

This commit is contained in:
Stormwind 2015-05-01 22:06:55 +02:00
parent ce6cfb7977
commit ebd5b88861
5 changed files with 62 additions and 0 deletions

1
spec/fixtures/json/test_01.json vendored Normal file
View File

@ -0,0 +1 @@
[1, 2, 3]

View File

@ -0,0 +1,11 @@
require 'spec_helper'
describe Rubella::Input::JSON, '.data' do
it "returns the stored data" do
input = Rubella::Input::JSON.string "[3, 4, 5]"
expect(input.data).to eq([3, 4, 5])
end
end

View File

@ -0,0 +1,16 @@
require 'spec_helper'
describe Rubella::Input::JSON, '.each' do
it "passes the data through the given block" do
input = Rubella::Input::JSON.string "[3, 4, 5]"
sum = 0
input.each do |value|
sum = sum + value
end
expect(sum).to eq(12)
end
end

View File

@ -0,0 +1,17 @@
require 'spec_helper'
describe Rubella::Input::JSON, '#self.file' do
it 'returns a Rubella::Input::JSON object' do
input = Rubella::Input::JSON.file 'spec/fixtures/json/test_01.json'
expect(input).to be_instance_of(Rubella::Input::JSON)
end
it "uses the given data" do
input = Rubella::Input::JSON.file 'spec/fixtures/json/test_01.json'
expect(input.data).to eq([1, 2, 3])
end
end

View File

@ -0,0 +1,17 @@
require 'spec_helper'
describe Rubella::Input::JSON, '#self.string' do
it 'returns a Rubella::Input::JSON object' do
input = Rubella::Input::JSON.string '[]'
expect(input).to be_instance_of(Rubella::Input::JSON)
end
it "uses the given data" do
input = Rubella::Input::JSON.string '[1, 2, 3]'
expect(input.data).to eq([1, 2, 3])
end
end