Skip to content
Browse files

#340353 Enumerable extensions covered by rspec

  • Loading branch information...
1 parent 0093de1 commit b240470c2db2328d2511f7638f417e84379cc96e s.averyanov committed Jul 27, 2012
Showing with 58 additions and 0 deletions.
  1. +58 −0 spec/pulse_meter/extensions/enumerable_spec.rb
View
58 spec/pulse_meter/extensions/enumerable_spec.rb
@@ -0,0 +1,58 @@
+require 'spec_helper'
+require 'pulse-meter/extensions/enumerable'
+
+describe Enumerable do
+ let!(:time) {Time.new}
+ describe "#convert_time" do
+ it "converts Time objects to unixtime" do
+ [time].convert_time.should == [time.to_i]
+ end
+
+ it "does not change other members" do
+ [1, 2, 3].convert_time.should == [1, 2 ,3]
+ end
+ end
+
+ describe "#to_table" do
+ context "when format is csv" do
+ it "returns csv as string" do
+ [].to_table(:csv).should be_instance_of(String)
+ end
+
+ it "returns csv containing each subarray as a row" do
+ [[:a, :b], [:c, :d]].to_table(:csv).should == "a;b\nc;d\n"
+ end
+
+ it "converts Time objects to unixtime" do
+ [[time]].to_table(:csv).should == "#{time.to_i}\n"
+ end
+
+ it "takes format argument both as string and as symbol" do
+ [[:foo]].to_table("csv").should == "foo\n"
+ [[:foo]].to_table(:csv).should == "foo\n"
+ end
+ end
+
+ context "when format is table" do
+ it "return Terminal::Table instance" do
+ [].to_table.should be_instance_of(Terminal::Table)
+ end
+
+ it "returns table containing each subarray as a row" do
+ data = [[:a, :b], [:c, :d]]
+ table = [[:a, :b], [:c, :d]].to_table
+ table.rows.map do |row|
+ row.cells.map(&:to_s).map(&:strip).map(&:to_sym)
+ end.should == data
+ end
+ end
+
+ it "uses table format as default" do
+ [].to_table.should be_instance_of(Terminal::Table)
+ end
+
+ it "uses table format unless it is :csv or 'csv'" do
+ [].to_table(:unknown_format).should be_instance_of(Terminal::Table)
+ end
+ end
+end

0 comments on commit b240470

Please sign in to comment.
Something went wrong with that request. Please try again.