"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "test/record_test.rb" between
ruport-1.7.1.tar.gz and ruport-1.8.0.tar.gz

About: Ruport (Ruby Reports) is a simple, extensible reporting system built for Rubyists. It provides tools for data acquisition, database interaction, formatting, and parsing/munging.

record_test.rb  (ruport-1.7.1):record_test.rb  (ruport-1.8.0)
skipping to change at line 13 skipping to change at line 13
class TestRecord < Minitest::Test class TestRecord < Minitest::Test
include Ruport::Data include Ruport::Data
def setup def setup
@attributes = %w[a b c d] @attributes = %w[a b c d]
@record = Ruport::Data::Record.new [1,2,3,4], :attributes => @attributes @record = Ruport::Data::Record.new [1,2,3,4], :attributes => @attributes
end end
describe "when initializing with an array with attributes" do context "when initializing with an array with attributes" do
def specify_key_access_should_work should "test_specify_key_access_should_work" do
assert_equal 1, @record["a"] assert_equal 1, @record["a"]
assert_equal 4, @record["d"] assert_equal 4, @record["d"]
assert_equal 2, @record.b assert_equal 2, @record.b
assert_equal 3, @record.c assert_equal 3, @record.c
assert_raises(NoMethodError) { @record.f } assert_raises(NoMethodError) { @record.f }
end end
def specify_ordinal_access_should_work should "test_specify_ordinal_access_should_work" do
assert_equal 1, @record[0] assert_equal 1, @record[0]
assert_equal 2, @record[1] assert_equal 2, @record[1]
assert_equal 3, @record[2] assert_equal 3, @record[2]
assert_equal 4, @record[3] assert_equal 4, @record[3]
end end
end end
describe "when initializing with an array without attributes" do context "when initializing with an array without attributes" do
def specify_ordinal_access_should_work should "test_specify_ordinal_access_should_work" do
record = Ruport::Data::Record.new [1,2,3,4] record = Ruport::Data::Record.new [1,2,3,4]
assert_equal 1, record[0] assert_equal 1, record[0]
assert_equal 2, record[1] assert_equal 2, record[1]
assert_equal 3, record[2] assert_equal 3, record[2]
assert_equal 4, record[3] assert_equal 4, record[3]
end end
end end
describe "when initializing with a hash without attributes" do describe "when initializing with a hash without attributes" do
def setup def setup
@record = Ruport::Data::Record.new({:a => 1, :b => 2, :c => 3},{}) @record = Ruport::Data::Record.new({:a => 1, :b => 2, :c => 3},{})
end end
def specify_key_access_should_work def test_specify_key_access_should_work
assert_equal 1, @record[:a] assert_equal 1, @record[:a]
assert_equal 2, @record[:b] assert_equal 2, @record[:b]
assert_equal 3, @record[:c] assert_equal 3, @record[:c]
assert_equal 3, @record.c assert_equal 3, @record.c
end end
end end
describe "when initializing with a hash with attributes" do describe "when initializing with a hash with attributes" do
def setup def setup
@record = Record.new({:a => 1, :b => 2, :c => 3 }, @record = Record.new({:a => 1, :b => 2, :c => 3 },
:attributes => [:c,:b,:a]) :attributes => [:c,:b,:a])
end end
def specify_key_access_should_work def test_specify_key_access_should_work
assert_equal 1, @record[:a] assert_equal 1, @record[:a]
assert_equal 2, @record[:b] assert_equal 2, @record[:b]
assert_equal 3, @record[:c] assert_equal 3, @record[:c]
assert_equal 3, @record.c assert_equal 3, @record.c
end end
def specify_ordinal_access_should_work def test_specify_ordinal_access_should_work
assert_equal 3, @record[0] assert_equal 3, @record[0]
assert_equal 2, @record[1] assert_equal 2, @record[1]
assert_equal 1, @record[2] assert_equal 1, @record[2]
end end
end end
def test_bracket_equals def test_bracket_equals
@record[1] = "godzilla" @record[1] = "godzilla"
@record["d"] = "mothra" @record["d"] = "mothra"
skipping to change at line 292 skipping to change at line 292
assert_equal(["a","b","c"], a.attributes) assert_equal(["a","b","c"], a.attributes)
end end
class MyRecordSub < Ruport::Data::Record; end class MyRecordSub < Ruport::Data::Record; end
def test_ensure_record_subclasses_render_properly def test_ensure_record_subclasses_render_properly
a = MyRecordSub.new [1,2,3] a = MyRecordSub.new [1,2,3]
assert_equal "1,2,3\n", a.to_csv assert_equal "1,2,3\n", a.to_csv
end end
describe "when rendering records" do context "when rendering records" do
def specify_record_as_should_work should "test_specify_record_as_should_work" do
rendered_row = @record.as(:text) rendered_row = @record.as(:text)
assert_equal("| 1 | 2 | 3 | 4 |\n", rendered_row) assert_equal("| 1 | 2 | 3 | 4 |\n", rendered_row)
end end
def specify_record_to_format_should_work_without_options should "test_specify_record_to_format_should_work_without_options" do
rendered_row = @record.to_text rendered_row = @record.to_text
assert_equal("| 1 | 2 | 3 | 4 |\n", rendered_row) assert_equal("| 1 | 2 | 3 | 4 |\n", rendered_row)
end end
def specify_record_to_format_should_work_with_options should "test_specify_record_to_format_should_work_with_options" do
rendered_row = @record.to_csv(:format_options => { :col_sep => "\t"}) rendered_row = @record.to_csv(:format_options => { :col_sep => "\t"})
assert_equal("1\t2\t3\t4\n",rendered_row) assert_equal("1\t2\t3\t4\n",rendered_row)
end end
describe "when given bad format names" do describe "when given bad format names" do
def setup def setup
@a = Record.new({ "a" => 1, "b" => 2 }) @a = Record.new({ "a" => 1, "b" => 2 })
end end
def specify_as_should_throw_proper_errors def test_specify_as_should_throw_proper_errors
assert_raises(Ruport::Controller::UnknownFormatError) { @a.as(:nothing) } assert_raises(Ruport::Controller::UnknownFormatError) { @a.as(:nothing) }
end end
def specify_to_format_should_throw_proper_errors def test_specify_to_format_should_throw_proper_errors
assert_raises(Ruport::Controller::UnknownFormatError) { @a.to_nothing } assert_raises(Ruport::Controller::UnknownFormatError) { @a.to_nothing }
end end
end end
## -- BUG TRAPS -------------------- ## -- BUG TRAPS --------------------
def specify_attributes_should_not_be_broken_by_to_hack should "test_specify_attributes_should_not_be_broken_by_to_hack" do
record = Ruport::Data::Record.new [1,2], :attributes => %w[a to_something] record = Ruport::Data::Record.new [1,2], :attributes => %w[a to_something]
assert_equal 2, record.to_something assert_equal 2, record.to_something
end end
end end
end end
 End of changes. 13 change blocks. 
15 lines changed or deleted 15 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)