spec/smoke/origin_spec.rb in benschwarz-smoke-0.3.7 vs spec/smoke/origin_spec.rb in benschwarz-smoke-0.3.9

- old
+ new

@@ -5,11 +5,11 @@ @origin = TestSource.source(:test) do emit do rename(:head => :title) sort(:title) - transform :title do |title| + transform :title, :name do |title| title.gsub(/Animal: /, '') end end end end @@ -22,11 +22,11 @@ it "should be ordered by title" do @origin.output.first[:title].should == "Kangaroo" end it "should output a single hash rather than a hash in an array when there is one item" do - Smoke[:test].truncate(1).output.should == {:title => "Kangaroo"} + Smoke[:test].truncate(1).output.should == {:title => "Kangaroo", :name => "Kelly"} end end describe "transformations" do it "should rename properties" do @@ -36,15 +36,15 @@ it "should sort by a given property" do Smoke[:test].sort(:header).output.first[:header].should == "Kangaroo" end it "should reverse the results" do - Smoke[:test].sort(:header).reverse.output.should == [{:header => "Platypus"}, {:header => "Kangaroo"}] + Smoke[:test].sort(:header).reverse.output.should == [{:header => "Platypus", :name => "Peter"}, {:header => "Kangaroo", :name => "Kelly"}] end it "should truncate results given a length" do - Smoke[:test].truncate(1).output.size.should == 1 + Smoke[:test].truncate(1).output.should be_an_instance_of(Hash) end describe "filtering" do before do TestSource.source(:keep) do @@ -67,19 +67,19 @@ it "should keep items" do Smoke[:keep].should(respond_to(:keep)) end it "should only contain items that match" do - Smoke[:keep].keep(:head, /^K/).output.should == {:head => "Kangaroo"} + Smoke[:keep].keep(:head, /^K/).output.should == {:head => "Kangaroo", :name => "Kelly"} end it "should discard items" do Smoke[:discard].should(respond_to(:discard)) end it "should not contain items that match" do - Smoke[:discard].discard(:head, /^K/).output.should == {:head => "Platypus"} + Smoke[:discard].discard(:head, /^K/).output.should == {:head => "Platypus", :name => "Peter"} end end end describe "output" do @@ -94,11 +94,11 @@ it "should output json" do @origin.output(:json).should =~ /^\[\{/ end it "should output yml" do - @origin.output(:yaml).should =~ /--- \n- :title:/ + @origin.output(:yaml).should =~ /^--- \n- :/ end it "should dispatch when output is called" do TestSource.source(:no_dispatch) Smoke[:no_dispatch].should_not_receive(:dispatch) @@ -115,11 +115,11 @@ transform :head do |head| head.gsub(/Animal: /, '') end end end - Smoke[:chain].rename(:head => :header).sort(:header).output.should == [{:header => "Kangaroo"}, {:header => "Platypus"}] + Smoke[:chain].rename(:head => :header).sort(:header).output.should == [{:header => "Kangaroo", :name => "Kelly"}, {:header => "Platypus", :name => "Peter"}] end it "should softly error when attempting to sort on a key that doesn't exist" do Smoke[:chain].sort(:header).should_not raise_error("NoMethodError") end @@ -188,14 +188,35 @@ describe "trasformations" do it "should respond to emit" do Smoke[:test].should respond_to(:emit) end + it "emit should require a block" do + lambda { Smoke[:test].emit }.should raise_error + lambda { Smoke[:test].emit {} }.should_not raise_error + end + it "should respond to transform" do Smoke[:test].should respond_to(:transform) end + it "tranform should require a block" do + lambda { Smoke[:test].transform }.should raise_error + lambda { Smoke[:test].transform {} }.should_not raise_error + end + it "should have at least one transformation" do - Smoke[:test].transformation.size.should == 1 + Smoke[:test].transformation.size.should_not be_nil + end + end + + describe "key insertion" do + it "should respond to insert" do + Smoke[:test].should respond_to(:insert) + end + + it "should insert values into each key" do + Smoke[:test].insert(:source, "twitter").output.first.should have_key :source + Smoke[:test].insert(:source, "twitter").output.first[:source].should == "twitter" end end end \ No newline at end of file