spec/smoke/origin_spec.rb in benschwarz-smoke-0.2.3 vs spec/smoke/origin_spec.rb in benschwarz-smoke-0.2.4
- old
+ new
@@ -16,10 +16,14 @@
end
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"}
+ end
end
describe "transformations" do
it "should rename properties" do
Smoke[:test].rename(:title => :header).output.first.should have_key(:header)
@@ -42,43 +46,60 @@
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"}
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"}
end
end
end
- it "should output" do
- @origin.output.should be_an_instance_of(Array)
+ describe "output" do
+ it "should output" do
+ @origin.output.should be_an_instance_of(Array)
+ end
+
+ it "should output two items" do
+ @origin.output.size.should == 2
+ end
+
+ it "should output json" do
+ @origin.output(:json).should =~ /^\[\{/
+ end
+
+ it "should output yml" do
+ @origin.output(:yaml).should =~ /--- \n- :title:/
+ end
+
+ it "should dispatch when output is called" do
+ TestSource.source(:no_dispatch)
+ Smoke[:no_dispatch].should_not_receive(:dispatch)
+
+ TestSource.source(:dispatch)
+ Smoke[:dispatch].should_receive(:dispatch)
+ Smoke[:dispatch].output
+ end
end
- it "should output two items" do
- @origin.output.size.should == 2
- end
-
- it "should output json" do
- @origin.output(:json).should =~ /^\[\{/
- end
-
- it "should output yml" do
- @origin.output(:yaml).should =~ /--- \n- :title:/
- end
-
it "method chaining" do
@source = TestSource.source(:chain)
@source.rename(:head => :header).sort(:header).output.should == [{:header => "Kangaroo"}, {:header => "Platypus"}]
end
it "should softly error when attempting to sort on a key that doesn't exist" do
TestSource.source(:chain).sort(:header).should_not raise_error("NoMethodError")
+ end
+
+ describe "variable injection" do
+ it "should allow variables to be left happlessly in your source definitions"
+ it "should allow setting of variables"
+ it "should error if output is called before a variable has been set"
end
end
\ No newline at end of file