diff --git a/spec/fixtures/json/test_01.json b/spec/fixtures/json/test_01.json new file mode 100644 index 0000000..b5d8bb5 --- /dev/null +++ b/spec/fixtures/json/test_01.json @@ -0,0 +1 @@ +[1, 2, 3] diff --git a/spec/unit/rubella/input/json/data_spec.rb b/spec/unit/rubella/input/json/data_spec.rb new file mode 100644 index 0000000..bd6bc67 --- /dev/null +++ b/spec/unit/rubella/input/json/data_spec.rb @@ -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 diff --git a/spec/unit/rubella/input/json/each_spec.rb b/spec/unit/rubella/input/json/each_spec.rb new file mode 100644 index 0000000..e60b3a8 --- /dev/null +++ b/spec/unit/rubella/input/json/each_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/unit/rubella/input/json/self_file_spec.rb b/spec/unit/rubella/input/json/self_file_spec.rb new file mode 100644 index 0000000..5c16431 --- /dev/null +++ b/spec/unit/rubella/input/json/self_file_spec.rb @@ -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 diff --git a/spec/unit/rubella/input/json/self_string_spec.rb b/spec/unit/rubella/input/json/self_string_spec.rb new file mode 100644 index 0000000..d5855a2 --- /dev/null +++ b/spec/unit/rubella/input/json/self_string_spec.rb @@ -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