diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..ae2274a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ +name: CI + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + ruby-version: + - head + - '3.2' + - '3.1' + - '3.0' + - '2.7' + - '2.6' + - '2.5' + - jruby + - jruby-9.3 + - jruby-9.2 + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true # 'bundle install' and cache + - name: Run tests + run: bundle exec rake diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b9c01a1..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: ruby -rvm: - - 2.4 - - 2.5 - - 2.6 - - 2.7 - - jruby-18mode - - jruby-19mode - diff --git a/spec/column_spec.rb b/spec/column_spec.rb index 7b9fe91..ce12b28 100644 --- a/spec/column_spec.rb +++ b/spec/column_spec.rb @@ -6,24 +6,24 @@ let(:c) {Column.new(:data => ["Once upon a time", "there was a dark and stormy night"], :name => :tagline)} it "remembers its name as a string" do - c.name.should == "tagline" + expect(c.name).to eq "tagline" end it "exposes the array of data representing the column" do - c.data.should == ["Once upon a time", "there was a dark and stormy night"] + expect(c.data).to eq ["Once upon a time", "there was a dark and stormy night"] end describe "#add_formatter" do it "stores the formatter" do f = {} c.add_formatter(f) - c.formatters.should == [f] + expect(c.formatters).to eq [f] end end describe "#formatter=" do it "adds the formatters individually" do - c.should_receive(:add_formatter).twice + expect(c).to receive(:add_formatter).twice c.formatters = [{}, {}] end end @@ -31,29 +31,29 @@ describe "#display_method" do it "returns the column's display method as a string" do c = Column.new(:display_method => :boofar) - c.display_method.should == "boofar" + expect(c.display_method).to eq "boofar" end it "doesn't turn a lambda display method into a string" do lam = lambda{} c = Column.new(:display_method => lam) - c.display_method.should == lam + expect(c.display_method).to eq lam end it "defaults to the column name" do c = Column.new(:name => :boofar) - c.display_method.should == "boofar" + expect(c.display_method).to eq "boofar" end end describe "#data_width" do it "reflects the width of the data set" do - c.data_width.should == 33 + expect(c.data_width).to eq 33 end it "includes the title in the calculation" do c.name = "a horse is a horse of course of course" - c.data_width.should == 38 + expect(c.data_width).to eq 38 end end @@ -61,32 +61,32 @@ context "when default width is specified" do it "uses the default width" do c.default_width = 10 - c.stub(:data_width => 15) - c.stub(:max_width => 20) - c.width.should == 10 + allow(c).to receive(:data_width).and_return(15) + allow(c).to receive(:max_width).and_return(20) + expect(c.width).to eq 10 end it "isn't limited by the config width" do c.default_width = 40 - c.stub(:data_width => 50) - c.stub(:max_width => 20) - c.width.should == 40 + allow(c).to receive(:data_width).and_return(50) + allow(c).to receive(:max_width).and_return(20) + expect(c.width).to eq 40 end end context "When default width is not specified" do it "uses the data width" do c.default_width = nil - c.stub(:data_width => 10) - c.stub(:max_width => 20) - c.width.should == 10 + allow(c).to receive(:data_width).and_return(10) + allow(c).to receive(:max_width).and_return(20) + expect(c.width).to eq 10 end it "is limited by the config width" do c.default_width = nil - c.stub(:data_width => 30) - c.stub(:max_width => 20) - c.width.should == 20 + allow(c).to receive(:data_width).and_return(30) + allow(c).to receive(:max_width).and_return(20) + expect(c.width).to eq 20 end end end diff --git a/spec/config_resolver_spec.rb b/spec/config_resolver_spec.rb index 1671f7a..9f32f3e 100644 --- a/spec/config_resolver_spec.rb +++ b/spec/config_resolver_spec.rb @@ -6,46 +6,46 @@ # Sandbox.add_class("Configged") # TablePrint::Config.set(Sandbox::Configged, [:title, :author]) # c = TablePrint::ConfigResolver.new(Object, Object, [:name]) - # c.columns.length.should == 2 - # c.columns.first.name.should == 'title' - # c.columns.last.name.should == 'author' + # expect(c.columns.length).to eq 2 + # expect(c.columns.first.name).to eq 'title' + # expect(c.columns.last.name).to eq 'author' #end describe "#get_and_remove" do it "deletes and returns the :except key from an array" do c = TablePrint::ConfigResolver.new(Object, []) options = [:title, :author, {:except => [:title]}] - c.get_and_remove(options, :except).should == [:title] - options.should == [:title, :author] + expect(c.get_and_remove(options, :except)).to eq [:title] + expect(options).to eq [:title, :author] end it "deletes and returns the :except key from an array with an :include key" do c = TablePrint::ConfigResolver.new(Object, []) options = [:title, {:except => [:title]}, {:include => [:author]}] - c.get_and_remove(options, :except).should == [:title] - options.should == [:title, {:include => [:author]}] + expect(c.get_and_remove(options, :except)).to eq [:title] + expect(options).to eq [:title, {:include => [:author]}] end it "deletes and returns the :except key from a hash with an :include key" do c = TablePrint::ConfigResolver.new(Object, []) options = [:title, {:except => [:title], :include => [:author]}] - c.get_and_remove(options, :except).should == [:title] - options.should == [:title, {:include => [:author]}] + expect(c.get_and_remove(options, :except)).to eq [:title] + expect(options).to eq [:title, {:include => [:author]}] end it "deletes and returns both the :include and :except keys" do c = TablePrint::ConfigResolver.new(Object, []) options = [:title, {:except => [:title]}, {:include => [:author]}] - c.get_and_remove(options, :include).should == [:author] - c.get_and_remove(options, :except).should == [:title] - options.should == [:title] + expect(c.get_and_remove(options, :include)).to eq [:author] + expect(c.get_and_remove(options, :except)).to eq [:title] + expect(options).to eq [:title] end it "works even if the array doesn't have an exception hash" do c = TablePrint::ConfigResolver.new(Object, []) options = [:title, :author] - c.get_and_remove(options, :except).should == [] - options.should == [:title, :author] + expect(c.get_and_remove(options, :except)).to eq [] + expect(options).to eq [:title, :author] end end @@ -53,23 +53,23 @@ context "with a symbol" do it "returns a column named foo" do c = TablePrint::ConfigResolver.new(Object, [:title], :foo) - c.columns.length.should == 1 - c.columns.first.name.should == 'foo' + expect(c.columns.length).to eq 1 + expect(c.columns.first.name).to eq 'foo' end end context "with a string" do it "returns a column named foo" do c = TablePrint::ConfigResolver.new(Object, [:title], 'foo') - c.columns.length.should == 1 - c.columns.first.name.should == 'foo' + expect(c.columns.length).to eq 1 + expect(c.columns.first.name).to eq 'foo' end end context "with an array of symbols and strings" do it "returns columns named foo and bar" do c = TablePrint::ConfigResolver.new(Object, [:title], :foo, 'bar') - c.columns.length.should == 2 - c.columns.first.name.should == 'foo' - c.columns.last.name.should == 'bar' + expect(c.columns.length).to eq 2 + expect(c.columns.first.name).to eq 'foo' + expect(c.columns.last.name).to eq 'bar' end end end @@ -78,29 +78,29 @@ context "with a symbol" do it "adds foo to the list of methods" do c = TablePrint::ConfigResolver.new(Object, [:title], :include => :foo) - c.columns.length.should == 2 - c.columns.first.name.should == 'title' - c.columns.last.name.should == 'foo' + expect(c.columns.length).to eq 2 + expect(c.columns.first.name).to eq 'title' + expect(c.columns.last.name).to eq 'foo' end end context "with an array" do it "adds foo and bar to the list of methods" do c = TablePrint::ConfigResolver.new(Object, [:title], :include => [:foo, :bar]) - c.columns.length.should == 3 - c.columns.first.name.should == 'title' - c.columns.last.name.should == 'bar' + expect(c.columns.length).to eq 3 + expect(c.columns.first.name).to eq 'title' + expect(c.columns.last.name).to eq 'bar' end end context "with options" do it "adds foo to the list of methods and remembers its options" do c = TablePrint::ConfigResolver.new(Object, [:title], :include => {:foo => {:width => 10}}) - c.columns.length.should == 2 - c.columns.first.name.should == 'title' + expect(c.columns.length).to eq 2 + expect(c.columns.first.name).to eq 'title' - c.columns.last.name.should == 'foo' - c.columns.last.default_width.should == 10 + expect(c.columns.last.name).to eq 'foo' + expect(c.columns.last.default_width).to eq 10 end end end @@ -109,15 +109,15 @@ context "with a symbol" do it "removes foo from the list of methods" do c = TablePrint::ConfigResolver.new(Object, [:title, :foo], :except => :foo) - c.columns.length.should == 1 - c.columns.first.name.should == 'title' + expect(c.columns.length).to eq 1 + expect(c.columns.first.name).to eq 'title' end end context "with an array" do it "removes foo and bar from the list of methods" do c = TablePrint::ConfigResolver.new(Object, [:title, :foo, :bar], :except => [:foo, 'bar']) - c.columns.length.should == 1 - c.columns.first.name.should == 'title' + expect(c.columns.length).to eq 1 + expect(c.columns.first.name).to eq 'title' end end end @@ -126,18 +126,18 @@ it "uses the key as the name and the lambda as the display method" do lam = lambda {} c = TablePrint::ConfigResolver.new(Object, [:title], :foo => {:display_method => lam}) - c.columns.length.should == 1 - c.columns.first.name.should == 'foo' - c.columns.first.display_method.should == lam + expect(c.columns.length).to eq 1 + expect(c.columns.first.name).to eq 'foo' + expect(c.columns.first.display_method).to eq lam end context "without the display_method keyword" do it "uses the key as the name and the lambda as the display method" do lam = lambda {} c = TablePrint::ConfigResolver.new(Object, [:title], :foo => lam) - c.columns.length.should == 1 - c.columns.first.name.should == 'foo' - c.columns.first.display_method.should == lam + expect(c.columns.length).to eq 1 + expect(c.columns.first.name).to eq 'foo' + expect(c.columns.first.display_method).to eq lam end end end @@ -145,37 +145,37 @@ describe "#usable_column_names" do it "returns default columns" do c = TablePrint::ConfigResolver.new(Object, [:title]) - c.usable_column_names.should == ['title'] + expect(c.usable_column_names).to eq ['title'] end it "returns specified columns instead of default columns" do c = TablePrint::ConfigResolver.new(Object, [:title], [:author]) - c.usable_column_names.should == ['author'] + expect(c.usable_column_names).to eq ['author'] end it "applies includes on top of default columns" do c = TablePrint::ConfigResolver.new(Object, [:title], [:include => :author]) - c.usable_column_names.should == ['title', 'author'] + expect(c.usable_column_names).to eq ['title', 'author'] end it "applies includes on top of specified columns" do c = TablePrint::ConfigResolver.new(Object, [:title], [:author, {:include => :pub_date}]) - c.usable_column_names.should == ['author', 'pub_date'] + expect(c.usable_column_names).to eq ['author', 'pub_date'] end it "applies excepts on top of default columns" do c = TablePrint::ConfigResolver.new(Object, [:title, :author], [:except => :author]) - c.usable_column_names.should == ['title'] + expect(c.usable_column_names).to eq ['title'] end it "applies excepts on top of specified columns" do c = TablePrint::ConfigResolver.new(Object, [:title, :author], [:pub_date, :length, {:except => :length}]) - c.usable_column_names.should == ['pub_date'] + expect(c.usable_column_names).to eq ['pub_date'] end it "applies both includes and excepts on top of specified columns" do c = TablePrint::ConfigResolver.new(Object, [:title, :author], [:pub_date, :length, {:except => :length, :include => :foobar}]) - c.usable_column_names.should == ['pub_date', 'foobar'] + expect(c.usable_column_names).to eq ['pub_date', 'foobar'] end end @@ -183,17 +183,17 @@ context "display_method" do it "sets the display method on the column" do c = TablePrint::ConfigResolver.new(Object, [:title], :title => {:display_method => :boofar}) - c.columns.length.should == 1 - c.columns.first.name.should == 'title' - c.columns.first.display_method.should == "boofar" + expect(c.columns.length).to eq 1 + expect(c.columns.first.name).to eq 'title' + expect(c.columns.first.display_method).to eq "boofar" end end context "width" do it "sets the default width" do c = TablePrint::ConfigResolver.new(Object, [:title], :title => {:width => 100}) - c.columns.length.should == 1 - c.columns.first.name.should == 'title' - c.columns.first.default_width.should == 100 + expect(c.columns.length).to eq 1 + expect(c.columns.first.name).to eq 'title' + expect(c.columns.first.default_width).to eq 100 end end context "formatters" do @@ -201,17 +201,17 @@ f1 = {} f2 = {} c = TablePrint::ConfigResolver.new(Object, [:title], :title => {:formatters => [f1, f2]}) - c.columns.length.should == 1 - c.columns.first.name.should == 'title' - c.columns.first.formatters.should == [f1, f2] + expect(c.columns.length).to eq 1 + expect(c.columns.first.name).to eq 'title' + expect(c.columns.first.formatters).to eq [f1, f2] end end context "display_name" do it "sets the display name on the column" do c = TablePrint::ConfigResolver.new(Object, [], :title => {:display_name => "Ti Tle"}) - c.columns.length.should == 1 - c.columns.first.name.should == 'Ti Tle' - c.columns.first.display_method.should == "title" + expect(c.columns.length).to eq 1 + expect(c.columns.first.name).to eq 'Ti Tle' + expect(c.columns.first.display_method).to eq "title" end end end @@ -221,22 +221,22 @@ it "returns a column named foo" do c = TablePrint::ConfigResolver.new(Object, []) column = c.option_to_column(:foo) - column.name.should == 'foo' + expect(column.name).to eq 'foo' end end context "with a string" do it "returns a column named foo" do c = TablePrint::ConfigResolver.new(Object, []) column = c.option_to_column('foo') - column.name.should == 'foo' + expect(column.name).to eq 'foo' end end context "with a hash" do it "returns a column named foo and the specified options" do c = TablePrint::ConfigResolver.new(Object, []) column = c.option_to_column({:foo => {:default_width => 10}}) - column.name.should == 'foo' - column.default_width.should == 10 + expect(column.name).to eq 'foo' + expect(column.default_width).to eq 10 end end end diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 5a09932..6853de7 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -2,18 +2,18 @@ describe TablePrint::Config do it "defaults max_width to 30" do - TablePrint::Config.max_width.should == 30 + expect(TablePrint::Config.max_width).to eq 30 end it "defaults time_format to year-month-day-hour-minute-second" do - TablePrint::Config.time_format.should == "%Y-%m-%d %H:%M:%S" + expect(TablePrint::Config.time_format).to eq "%Y-%m-%d %H:%M:%S" end describe "individual config options" do describe "storing and retrieving" do it "sets the variable" do TablePrint::Config.set(:max_width, [10]) - TablePrint::Config.max_width.should == 10 + expect(TablePrint::Config.max_width).to eq 10 TablePrint::Config.set(:max_width, [30]) end end @@ -22,7 +22,7 @@ it "resets the variable to its initial value" do TablePrint::Config.set(:max_width, [10]) TablePrint::Config.clear(:max_width) - TablePrint::Config.max_width.should == 30 + expect(TablePrint::Config.max_width).to eq 30 end end end @@ -35,7 +35,7 @@ describe "storing and retrieving" do it "stores the column hash" do TablePrint::Config.set(Sandbox::Blog, [:title, :author]) - TablePrint::Config.for(Sandbox::Blog).should == [:title, :author] + expect(TablePrint::Config.for(Sandbox::Blog)).to eq [:title, :author] end end @@ -43,7 +43,7 @@ it "removes the class from storage" do TablePrint::Config.set(Sandbox::Blog, [:title, :author]) TablePrint::Config.clear(Sandbox::Blog) - TablePrint::Config.for(Sandbox::Blog).should be_nil + expect(TablePrint::Config.for(Sandbox::Blog)).to be_nil end end end @@ -57,20 +57,20 @@ it "accepts object that respond to puts" do myIO = Sandbox::MyIO.new TablePrint::Config.set(:io, [myIO]) - TablePrint::Config.io.should == myIO + expect(TablePrint::Config.io).to eq myIO end it "doesn't accept objects unless they respond to puts" do - lambda { + expect { TablePrint::Config.set(:io, [""]) - }.should raise_error StandardError + }.to raise_error StandardError end it "defaults to STDOUT" do myIO = Sandbox::MyIO.new TablePrint::Config.set(:io, [myIO]) TablePrint::Config.clear(:io) - TablePrint::Config.io.should == STDOUT + expect(TablePrint::Config.io).to eq STDOUT end end end diff --git a/spec/fingerprinter_spec.rb b/spec/fingerprinter_spec.rb index fb91437..9ae2ff4 100644 --- a/spec/fingerprinter_spec.rb +++ b/spec/fingerprinter_spec.rb @@ -15,52 +15,52 @@ class TablePrint::Row describe "#lift" do it "turns a single level of columns into a single row" do rows = Fingerprinter.new.lift([Column.new(:name => "name")], OpenStruct.new(:name => "dale carnegie")) - rows.length.should == 1 + expect(rows.length).to eq 1 row = rows.first - row.children.length.should == 0 - row.cells.should == {'name' => "dale carnegie"} + expect(row.children.length).to eq 0 + expect(row.cells).to eq({'name' => "dale carnegie"}) end it "uses the display_method to get the data" do rows = Fingerprinter.new.lift([Column.new(:name => "name of work", :display_method => "title")], OpenStruct.new(:title => "of mice and men")) - rows.length.should == 1 + expect(rows.length).to eq 1 row = rows.first - row.children.length.should == 0 - row.cells.should == {'name of work' => "of mice and men"} + expect(row.children.length).to eq 0 + expect(row.cells).to eq({'name of work' => "of mice and men"}) end it "turns multiple levels of columns into multiple rows" do rows = Fingerprinter.new.lift([Column.new(:name => "name"), Column.new(:name => "books.title")], OpenStruct.new(:name => "dale carnegie", :books => [OpenStruct.new(:title => "how to make influences")])) - rows.length.should == 1 + expect(rows.length).to eq 1 row = rows.first - row.children.length.should == 1 - row.cells.should == {'name' => "dale carnegie"} - row.children.first.children.first.cells.should == {'books.title' => "how to make influences"} + expect(row.children.length).to eq 1 + expect(row.cells).to eq({'name' => "dale carnegie"}) + expect(row.children.first.children.first.cells).to eq({'books.title' => "how to make influences"}) end it "doesn't choke if an association doesn't exist" do rows = Fingerprinter.new.lift([Column.new(:name => "name"), Column.new(:name => "books.title")], OpenStruct.new(:name => "dale carnegie", :books => [])) - rows.length.should == 1 + expect(rows.length).to eq 1 row = rows.first - row.children.length.should == 0 + expect(row.children.length).to eq 0 end it "allows a lambda as the display_method" do rows = Fingerprinter.new.lift([Column.new(:name => "name", :display_method => lambda { |row| row.name.gsub(/[aeiou]/, "") })], OpenStruct.new(:name => "dale carnegie")) - rows.length.should == 1 + expect(rows.length).to eq 1 row = rows.first - row.children.length.should == 0 - row.cells.should == {'name' => "dl crng"} + expect(row.children.length).to eq 0 + expect(row.cells).to eq({'name' => "dl crng"}) end it "doesn't puke if a lambda returns nil" do rows = Fingerprinter.new.lift([Column.new(:name => "name", :display_method => lambda { |row| nil })], OpenStruct.new(:name => "dale carnegie")) - rows.length.should == 1 + expect(rows.length).to eq 1 row = rows.first - row.children.length.should == 0 - row.cells.should == {'name' => nil} + expect(row.children.length).to eq 0 + expect(row.cells).to eq({'name' => nil}) end end @@ -69,25 +69,25 @@ class TablePrint::Row f = Fingerprinter.new f.instance_variable_set("@column_names_by_display_method", {"name" => "name"}) rows = f.hash_to_rows("", {'name' => {}}, OpenStruct.new(:name => "dale carnegie")) - rows.length.should == 1 + expect(rows.length).to eq 1 row = rows.first - row.children.length.should == 0 - row.cells.should == {'name' => 'dale carnegie'} + expect(row.children.length).to eq 0 + expect(row.cells).to eq({'name' => 'dale carnegie'}) end it 'recurses for subsequent levels of hash' do f = Fingerprinter.new f.instance_variable_set("@column_names_by_display_method", {"name" => "name", "books.title" => "books.title"}) rows = f.hash_to_rows("", {'name' => {}, 'books' => {'title' => {}}}, [OpenStruct.new(:name => 'dale carnegie', :books => [OpenStruct.new(:title => "hallmark")])]) - rows.length.should == 1 + expect(rows.length).to eq 1 top_row = rows.first - top_row.cells.should == {'name' => 'dale carnegie'} - top_row.children.length.should == 1 - top_row.children.first.child_count.should == 1 + expect(top_row.cells).to eq({'name' => 'dale carnegie'}) + expect(top_row.children.length).to eq 1 + expect(top_row.children.first.child_count).to eq 1 bottom_row = top_row.children.first.children.first - bottom_row.cells.should == {'books.title' => 'hallmark'} + expect(bottom_row.cells).to eq({'books.title' => 'hallmark'}) end end @@ -96,21 +96,21 @@ class TablePrint::Row f = Fingerprinter.new f.instance_variable_set("@column_names_by_display_method", {"title" => "title", "author" => "author"}) row = f.populate_row("", {'title' => {}, 'author' => {}, 'publisher' => {'address' => {}}}, OpenStruct.new(:title => "foobar", :author => "bobby")) - row.cells.should == {'title' => "foobar", 'author' => 'bobby'} + expect(row.cells).to eq({'title' => "foobar", 'author' => 'bobby'}) end it "uses the provided prefix to name the cells" do f = Fingerprinter.new f.instance_variable_set("@column_names_by_display_method", {"bar.title" => "bar.title", "bar.author" => "bar.author"}) row = f.populate_row("bar", {'title' => {}, 'author' => {}, 'publisher' => {'address' => {}}}, OpenStruct.new(:title => "foobar", :author => "bobby")) - row.cells.should == {'bar.title' => "foobar", 'bar.author' => 'bobby'} + expect(row.cells).to eq({'bar.title' => "foobar", 'bar.author' => 'bobby'}) end it "uses the column name as the cell name but uses the display method to get the value" do f = Fingerprinter.new f.instance_variable_set("@column_names_by_display_method", {"bar.title" => "title", "bar.author" => "bar.author"}) row = f.populate_row("bar", {'title' => {}, 'author' => {}, 'publisher' => {'address' => {}}}, OpenStruct.new(:title => "foobar", :author => "bobby")) - row.cells.should == {'title' => "foobar", 'bar.author' => 'bobby'} + expect(row.cells).to eq({'title' => "foobar", 'bar.author' => 'bobby'}) end context 'using a hash as input_data' do @@ -119,7 +119,7 @@ class TablePrint::Row f.instance_variable_set('@column_names_by_display_method', {'title' => 'title', 'author' => 'author'}) input_data = {:title => 'foobar', :author => 'bobby'} row = f.populate_row('', {'title' => {}, 'author' => {}, 'publisher' => {'address' => {}}}, input_data) - row.cells.should == {'title' => 'foobar', 'author' => 'bobby'} + expect(row.cells).to eq({'title' => 'foobar', 'author' => 'bobby'}) end it "fills a row by calling methods on the target object" do @@ -127,7 +127,7 @@ class TablePrint::Row f.instance_variable_set('@column_names_by_display_method', {'title' => 'title', 'author' => 'author'}) input_data = {'title' => 'foobar', 'author' => 'bobby'} row = f.populate_row('', {'title' => {}, 'author' => {}, 'publisher' => {'address' => {}}}, input_data) - row.cells.should == {'title' => 'foobar', 'author' => 'bobby'} + expect(row.cells).to eq({'title' => 'foobar', 'author' => 'bobby'}) end end @@ -136,7 +136,7 @@ class TablePrint::Row f = Fingerprinter.new f.instance_variable_set('@column_names_by_display_method', {'foo' => 'foo'}) row = f.populate_row('', {'foo' => {}}, Hash.new) - row.cells.should == {'foo' => 'Method Missing'} + expect(row.cells).to eq({'foo' => 'Method Missing'}) end end end @@ -146,38 +146,38 @@ class TablePrint::Row f = Fingerprinter.new books = [] - f.should_receive(:hash_to_rows).with("author.books", {'title' => {}}, books).and_return([]) + expect(f).to receive(:hash_to_rows).with("author.books", {'title' => {}}, books).and_return([]) groups = f.create_child_group("author", {'books' => {'title' => {}}}, OpenStruct.new(:name => "bobby", :books => books)) - groups.length.should == 1 - groups.first.should be_a TablePrint::RowGroup + expect(groups.length).to eq 1 + expect(groups.first).to be_a TablePrint::RowGroup end end describe "#columns_to_handle" do it "returns hash keys that have an empty hash as the value" do - Fingerprinter.new.handleable_columns({'name' => {}, 'books' => {'title' => {}}}).should == ["name"] + expect(Fingerprinter.new.handleable_columns({'name' => {}, 'books' => {'title' => {}}})).to eq(["name"]) end end describe "#columns_to_pass" do it "returns hash keys that do not have an empty hash as the value" do - Fingerprinter.new.passable_columns({'name' => {}, 'books' => {'title' => {}}}).should == ["books"] + expect(Fingerprinter.new.passable_columns({'name' => {}, 'books' => {'title' => {}}})).to eq(["books"]) end end describe "#chain_to_nested_hash" do it "turns a list of methods into a nested hash" do - Fingerprinter.new.display_method_to_nested_hash("books").should == {'books' => {}} - Fingerprinter.new.display_method_to_nested_hash("reviews.user").should == {'reviews' => {'user' => {}}} + expect(Fingerprinter.new.display_method_to_nested_hash("books")).to eq({'books' => {}}) + expect(Fingerprinter.new.display_method_to_nested_hash("reviews.user")).to eq({'reviews' => {'user' => {}}}) end end describe "#columns_to_nested_hash" do it "splits the column names into a nested hash" do - Fingerprinter.new.display_methods_to_nested_hash(["books.name"]).should == {'books' => {'name' => {}}} - Fingerprinter.new.display_methods_to_nested_hash( + expect(Fingerprinter.new.display_methods_to_nested_hash(["books.name"])).to eq({'books' => {'name' => {}}}) + expect(Fingerprinter.new.display_methods_to_nested_hash( ["books.name", "books.publisher", "reviews.rating", "reviews.user.email", "reviews.user.id"] - ).should == {'books' => {'name' => {}, 'publisher' => {}}, 'reviews' => {'rating' => {}, 'user' => {'email' => {}, 'id' => {}}}} + )).to eq({'books' => {'name' => {}, 'publisher' => {}}, 'reviews' => {'rating' => {}, 'user' => {'email' => {}, 'id' => {}}}}) end end end diff --git a/spec/formatter_spec.rb b/spec/formatter_spec.rb index 07c464c..584e810 100644 --- a/spec/formatter_spec.rb +++ b/spec/formatter_spec.rb @@ -6,19 +6,19 @@ describe "#format" do it "only operates on Time objects" do f = TablePrint::TimeFormatter.new - f.format(12).should == 12 + expect(f.format(12)).to eq 12 end it "uses the config'd time_format" do f = TablePrint::TimeFormatter.new time = Time.local(2012, 01, 11, 1, 23, 45) - f.format(time).should == "2012-01-11 01:23:45" # default time format is set in config.rb + expect(f.format(time)).to eq "2012-01-11 01:23:45" # default time format is set in config.rb end it "overrides the config'd time format with one it was passed" do f = TablePrint::TimeFormatter.new("%Y") time = Time.local(2012, 01, 11, 1, 23, 45) - f.format(time).should == "2012" # default time format is set in config.rb + expect(f.format(time)).to eq "2012" # default time format is set in config.rb end end end @@ -30,11 +30,11 @@ describe "#format" do it "replaces carriage returns with spaces" do - @f.format("foo\r\nbar").should == "foo bar" + expect(@f.format("foo\r\nbar")).to eq "foo bar" end it "replaces newlines with spaces" do - @f.format("foo\nbar").should == "foo bar" + expect(@f.format("foo\nbar")).to eq "foo bar" end end end @@ -46,19 +46,19 @@ describe "#format" do it "pads a short field to the specified width" do - @f.format("asdf").should == "asdf " + expect(@f.format("asdf")).to eq "asdf " end it "truncates long fields with periods" do - @f.format("1234567890123456").should == "1234567..." + expect(@f.format("1234567890123456")).to eq "1234567..." end it "uses an empty string in place of nils" do - @f.format(nil).should == " " + expect(@f.format(nil)).to eq " " end it "turns objects into strings before trying to format them" do - @f.format(123).should == "123 " + expect(@f.format(123)).to eq "123 " end end end diff --git a/spec/hash_extensions_spec.rb b/spec/hash_extensions_spec.rb index 0a7d058..d1176c2 100644 --- a/spec/hash_extensions_spec.rb +++ b/spec/hash_extensions_spec.rb @@ -5,7 +5,7 @@ x = {'reviews' => {'user' => {}}} y = {'reviews' => {'ratings' => {}}} x.extend TablePrint::HashExtensions::ConstructiveMerge - x.constructive_merge(y).should == {'reviews' => {'user' => {}, 'ratings' => {}}} + expect(x.constructive_merge(y)).to eq({'reviews' => {'user' => {}, 'ratings' => {}}}) end end @@ -15,6 +15,6 @@ y = {'reviews' => {'ratings' => {}}} x.extend TablePrint::HashExtensions::ConstructiveMerge x.constructive_merge!(y) - x.should == {'reviews' => {'user' => {}, 'ratings' => {}}} + expect(x).to eq({'reviews' => {'user' => {}, 'ratings' => {}}}) end end diff --git a/spec/printable_spec.rb b/spec/printable_spec.rb index b68d471..a9b8171 100644 --- a/spec/printable_spec.rb +++ b/spec/printable_spec.rb @@ -11,7 +11,7 @@ Sandbox.add_attributes("Hat", "brand") p = Sandbox::Hat.new - TablePrint::Printable.default_display_methods(p).should == %W(brand) + expect(TablePrint::Printable.default_display_methods(p)).to eq %W(brand) end it "ignores dangerous methods" do @@ -19,7 +19,7 @@ Sandbox.add_method("Hat", "brand!") {} p = Sandbox::Hat.new - TablePrint::Printable.default_display_methods(p).should == [] + expect(TablePrint::Printable.default_display_methods(p)).to eq [] end it "ignores methods defined in a superclass" do @@ -28,7 +28,7 @@ Sandbox.add_attributes("Hat::Bowler", "brim_width") p = Sandbox::Hat::Bowler.new - TablePrint::Printable.default_display_methods(p).should == %W(brim_width) + expect(TablePrint::Printable.default_display_methods(p)).to eq %W(brim_width) end it "ignores methods that require arguments" do @@ -37,11 +37,11 @@ Sandbox.add_method("Hat", "tip?") { |person| person.rapscallion? } p = Sandbox::Hat.new - TablePrint::Printable.default_display_methods(p).should == %W(brand) + expect(TablePrint::Printable.default_display_methods(p)).to eq %W(brand) end it "ignores methods from an included module" do - pending "waiting for Cat to support module manipulation" + skip "waiting for Cat to support module manipulation" end it "uses column information when available (eg, from ActiveRecord objects)" @@ -51,7 +51,7 @@ obj = test_struct.new obj.foo = 1 obj.bar = 2 - TablePrint::Printable.default_display_methods(obj).should == [:foo, :bar] + expect(TablePrint::Printable.default_display_methods(obj)).to eq [:foo, :bar] end diff --git a/spec/returnable_spec.rb b/spec/returnable_spec.rb index 558c760..4a59d17 100644 --- a/spec/returnable_spec.rb +++ b/spec/returnable_spec.rb @@ -3,29 +3,29 @@ describe TablePrint::Returnable do it "returns its initialized value from its to_s method" do r = TablePrint::Returnable.new("foobar") - r.to_s.should == "foobar" + expect(r.to_s).to eq "foobar" end it "returns its initialized value from its inspect method" do # 1.8.7 calls inspect on return values r = TablePrint::Returnable.new("foobar") - r.inspect.should == "foobar" + expect(r.inspect).to eq "foobar" end it "passes #set through to TablePrint::Config" do - TablePrint::Config.should_receive(:set).with(Object, [:foo]) + expect(TablePrint::Config).to receive(:set).with(Object, [:foo]) r = TablePrint::Returnable.new r.set(Object, :foo) end it "passes #clear through to TablePrint::Config" do - TablePrint::Config.should_receive(:clear).with(Object) + expect(TablePrint::Config).to receive(:clear).with(Object) r = TablePrint::Returnable.new r.clear(Object) end it "passes #config_for through to TablePrint::Config.for" do - TablePrint::Config.should_receive(:for).with(Object) + expect(TablePrint::Config).to receive(:for).with(Object) r = TablePrint::Returnable.new r.config_for(Object) end diff --git a/spec/row_group_spec.rb b/spec/row_group_spec.rb index d187b57..25440f8 100644 --- a/spec/row_group_spec.rb +++ b/spec/row_group_spec.rb @@ -10,19 +10,19 @@ it "assigns the column object to the column name" do column = Column.new(:name => "foobar") parent.set_column(column) - parent.column_for(:foobar).should == column + expect(parent.column_for(:foobar)).to eq column end end describe "#add_child" do it "adds the child to my children" do parent.add_child(child) - parent.child_count.should == 1 + expect(parent.child_count).to eq 1 end it "sets me as my child's parent" do parent.add_child(child) - child.parent.should == parent + expect(child.parent).to eq parent end end @@ -31,13 +31,13 @@ it "adds all the children to myself" do parent.add_children([child, child2]) - parent.child_count.should == 2 + expect(parent.child_count).to eq 2 end it "sets me as their parent" do parent.add_children([child, child2]) - child.parent.should == parent - child2.parent.should == parent + expect(child.parent).to eq parent + expect(child2.parent).to eq parent end end @@ -46,17 +46,17 @@ child.set_cell_values(:title => 'foobar') parent.add_child(child) - parent.columns.length.should == 1 - parent.columns.first.name.should == 'title' - parent.columns.first.data.should == ['foobar'] + expect(parent.columns.length).to eq 1 + expect(parent.columns.first.name).to eq 'title' + expect(parent.columns.first.data).to eq ['foobar'] end it "gets the columns from the root node" do parent.add_child(child) child.set_cell_values(:title => 'foobar') - parent.columns.length.should == 1 - child.columns.should == parent.columns + expect(parent.columns.length).to eq 1 + expect(child.columns).to eq parent.columns end end @@ -65,7 +65,7 @@ parent.add_child(child) child.set_cell_values(:title => 'foobar') column = parent.columns.first - parent.column_for(:title).should == column + expect(parent.column_for(:title)).to eq column end end @@ -76,7 +76,7 @@ column = parent.columns.first parent.add_formatter(:title, {}) - column.formatters.should == [{}] + expect(column.formatters).to eq [{}] end end @@ -88,7 +88,7 @@ r1.set_cell_values(:title => 'foobar') r2.set_cell_values(:subtitle => 'elemental') - parent.width.should == 18 + expect(parent.width).to eq 18 end end @@ -99,13 +99,13 @@ r1.set_cell_values(:title => 'a' * 5, :description => 'b' * 3, :category => 'c' * 10) r2.set_cell_values(:title => 'a' * 6, :description => 'b' * 4, :category => 'c' * 9) - parent.header.size.should == parent.horizontal_separator.size + expect(parent.header.size).to eq parent.horizontal_separator.size compare_rows(parent.horizontal_separator, '-' * 6 + '-|-' + '-' * 'description'.size + '-|-' + '-' * 10) end it "matches the header width" do child.set_cell_values(:title => 'foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar') - child.horizontal_separator.should == '------------------------------' # 30 hyphens + expect(child.horizontal_separator).to eq '------------------------------' # 30 hyphens end end @@ -123,15 +123,15 @@ group = RowGroup.new group.add_child(Row.new.set_cell_values(:title => 'foo')) group.add_child(Row.new.set_cell_values(:title => 'bar')) - group.raw_column_data(:title).should == ['foo', 'bar'] + expect(group.raw_column_data(:title)).to eq ['foo', 'bar'] end end end def compare_rows(actual_rows, expected_rows) - actual_rows.split("\n").length.should == expected_rows.split("\n").length + expect(actual_rows.split("\n").length).to eq expected_rows.split("\n").length actual_rows.split("\n").zip(expected_rows.split("\n")).each do |actual, expected| - actual.split(//).sort.join.should == expected.split(//).sort.join + expect(actual.split(//).sort.join).to eq expected.split(//).sort.join end end @@ -160,16 +160,16 @@ def compare_rows(actual_rows, expected_rows) f1 = Sandbox::DoubleFormatter.new f2 = Sandbox::ChopFormatter.new - row.stub(:column_for) {OpenStruct.new(:width => 11, :formatters => [f1, f2])} + allow(row).to receive(:column_for).and_return(OpenStruct.new(:width => 11, :formatters => [f1, f2])) - row.apply_formatters(:title, "foobar").should == "foobarfooba" + expect(row.apply_formatters(:title, "foobar")).to eq "foobarfooba" end it "uses the config'd time_format to format times" do - row.stub(:column_for) {OpenStruct.new(:width => 20, :formatters => [], :time_format => "%Y %m %d")} + allow(row).to receive(:column_for).and_return(OpenStruct.new(:width => 20, :formatters => [], :time_format => "%Y %m %d")) time_formatter = TablePrint::TimeFormatter.new - TablePrint::TimeFormatter.should_receive(:new).with("%Y %m %d") {time_formatter} + expect(TablePrint::TimeFormatter).to receive(:new).with("%Y %m %d") {time_formatter} row.apply_formatters(:title, Time.local(2012, 6, 1, 14, 20, 20)) end end @@ -184,7 +184,7 @@ def compare_rows(actual_rows, expected_rows) end row.add_child(group) - row.raw_column_data('title').should == ['one', 'two', 'three', 'four', 'five', 'six', 'seven'] + expect(row.raw_column_data('title')).to eq ['one', 'two', 'three', 'four', 'five', 'six', 'seven'] end end @@ -206,11 +206,11 @@ def compare_rows(actual_rows, expected_rows) end it "pulls the cells up into the parent" do - @row.cells.should == {"foo" => "foo", "bar" => "bar"} + expect(@row.cells).to eq({"foo" => "foo", "bar" => "bar"}) end it "dereferences the now-defunct group" do - @row.children.length.should == 0 + expect(@row.children.length).to eq 0 end end @@ -233,13 +233,13 @@ def compare_rows(actual_rows, expected_rows) end it "pulls the cells from the first row up into the parent" do - @row.cells.should == {"foo" => "foo", "bar" => "bar"} + expect(@row.cells).to eq({"foo" => "foo", "bar" => "bar"}) end it "deletes the absorbed row but leaves the second row in the group" do - @row.children.length.should == 1 - @row.children.first.children.length.should == 1 - @row.children.first.children.first.cells.should == {"bar" => "baz"} + expect(@row.children.length).to eq 1 + expect(@row.children.first.children.length).to eq 1 + expect(@row.children.first.children.first.cells).to eq({"bar" => "baz"}) end end @@ -264,11 +264,11 @@ def compare_rows(actual_rows, expected_rows) end it "pulls the cells from both groups into the parent" do - @row.cells.should == {"foo" => "foo", "bar" => "bar", "baz" => "baz"} + expect(@row.cells).to eq({"foo" => "foo", "bar" => "bar", "baz" => "baz"}) end it "dereferences both now-defunct groups" do - @row.children.length.should == 0 + expect(@row.children.length).to eq 0 end end @@ -290,11 +290,11 @@ def compare_rows(actual_rows, expected_rows) end it "pulls the cells from both groups into the parent" do - @row.cells.should == {"foo" => "foo", "bar" => "bar"} + expect(@row.cells).to eq({"foo" => "foo", "bar" => "bar"}) end it "dereferences both now-defunct groups" do - @row.children.length.should == 0 + expect(@row.children.length).to eq 0 end end @@ -322,13 +322,13 @@ def compare_rows(actual_rows, expected_rows) end it "pulls the single row and the first row from the double into itself" do - @row.cells.should == {"foo" => "foo", "bar" => "bar", "baz" => "baz"} + expect(@row.cells).to eq({"foo" => "foo", "bar" => "bar", "baz" => "baz"}) end it "keeps the second row from the second group in its own group" do - @row.children.length.should == 1 - @row.children.first.children.length.should == 1 - @row.children.first.children.first.cells.should == {"baz" => "bazaar"} + expect(@row.children.length).to eq 1 + expect(@row.children.first.children.length).to eq 1 + expect(@row.children.first.children.first.cells).to eq({"baz" => "bazaar"}) end end @@ -354,11 +354,11 @@ def compare_rows(actual_rows, expected_rows) end it "pulls the cells from both groups into the parent" do - @row.cells.should == {"foo" => "foo", "bar" => "bar", "baz" => "baz"} + expect(@row.cells).to eq({"foo" => "foo", "bar" => "bar", "baz" => "baz"}) end it "dereferences both now-defunct groups" do - @row.children.length.should == 0 + expect(@row.children.length).to eq 0 end end @@ -387,13 +387,13 @@ def compare_rows(actual_rows, expected_rows) end it "pulls the first row from each group up into itself" do - @row.cells.should == {"foo" => "foo", "bar" => "bar", "baz" => "baz"} + expect(@row.cells).to eq({"foo" => "foo", "bar" => "bar", "baz" => "baz"}) end it "deletes only the intermediary group" do - @row.children.length.should == 1 - @row.children.first.children.length.should == 1 - @row.children.first.children.first.cells.should == {"baz" => "bazaar"} + expect(@row.children.length).to eq 1 + expect(@row.children.first.children.length).to eq 1 + expect(@row.children.first.children.first.cells).to eq({"baz" => "bazaar"}) end end @@ -425,19 +425,19 @@ def compare_rows(actual_rows, expected_rows) end it "pulls the first row from the first group into the parent" do - @row.cells.should == {"foo" => "foo", "bar" => "bar"} + expect(@row.cells).to eq({"foo" => "foo", "bar" => "bar"}) end it "leaves the second row in the first group" do - @row.children.length.should == 2 - @row.children.first.children.length.should == 1 - @row.children.first.children.first.cells.should == {"bar" => "bar2"} + expect(@row.children.length).to eq 2 + expect(@row.children.first.children.length).to eq 1 + expect(@row.children.first.children.first.cells).to eq({"bar" => "bar2"}) end it "leaves the second group alone" do - @row.children.last.children.length.should == 2 - @row.children.last.children.first.cells.should == {"baz" => "bazaar"} - @row.children.last.children.last.cells.should == {"baz" => "bazaar2"} + expect(@row.children.last.children.length).to eq 2 + expect(@row.children.last.children.first.cells).to eq({"baz" => "bazaar"}) + expect(@row.children.last.children.last.cells).to eq({"baz" => "bazaar2"}) end end @@ -478,16 +478,16 @@ def compare_rows(actual_rows, expected_rows) end it "pulls the first row from the first child into itself" do - @row.cells.should == {"foo" => "foo", "bar" => "bar", "barry" => "bare"} + expect(@row.cells).to eq({"foo" => "foo", "bar" => "bar", "barry" => "bare"}) end it "leaves the second row from the first child in the first group" do - @row.children.first.children.first.cells.should == {"barry" => "bart"} + expect(@row.children.first.children.first.cells).to eq({"barry" => "bart"}) end it "collapses the second group" do - @row.children.last.children.first.cells.should == {"bar" => "baz", "barry" => "bazaar"} - @row.children.last.children.first.children.first.children.first.cells.should == {"barry" => "bizarre"} + expect(@row.children.last.children.first.cells).to eq ({"bar" => "baz", "barry" => "bazaar"}) + expect(@row.children.last.children.first.children.first.children.first.cells).to eq({"barry" => "bizarre"}) end end end diff --git a/spec/table_print_spec.rb b/spec/table_print_spec.rb index d8c86ff..5eafd81 100644 --- a/spec/table_print_spec.rb +++ b/spec/table_print_spec.rb @@ -11,7 +11,7 @@ describe "printing an empty array" do it "returns the string 'no data'" do p = Printer.new([]) - p.table_print.should == 'No data.' + expect(p.table_print).to eq 'No data.' end end @@ -20,14 +20,14 @@ Sandbox.add_class("Blog") Sandbox.add_attributes("Blog", :author) p = Printer.new(Sandbox::Blog.new, "author.name") - p.table_print.should == 'No data.' + expect(p.table_print).to eq 'No data.' end end describe "message" do it "defaults to the time the print took, but in string" do message = Printer.new([]).message - message.should be_a String + expect(message).to be_a String expect(message.to_f.to_s).to eq(message) end @@ -36,7 +36,7 @@ tp.set Sandbox::User, :id, :email p = Printer.new(Sandbox::User.new) - p.message.should == "Printed with config" + expect(p.message).to eq "Printed with config" end end @@ -48,8 +48,8 @@ p = Printer.new(Sandbox::Post.new) cols = p.send(:columns) - cols.length.should == 1 - cols.first.name.should == 'title' + expect(cols.length).to eq 1 + expect(cols.first.name).to eq 'title' end it 'pull the column names off of the array of Structs' do @@ -57,8 +57,8 @@ data = [struct.new("User 1", "Familyname 1"), struct.new("User 2", "Familyname 2")] p = Printer.new(data) cols = p.send(:columns) - cols.length.should == 2 - cols.collect(&:name).sort.should == ['name', 'surname'] + expect(cols.length).to eq 2 + expect(cols.collect(&:name).sort).to eq ['name', 'surname'] end context 'when keys are symbols' do @@ -71,8 +71,8 @@ p = Printer.new(data) cols = p.send(:columns) - cols.length.should == 2 - cols.collect(&:name).sort.should == ['name', 'surname'] + expect(cols.length).to eq 2 + expect(cols.collect(&:name).sort).to eq ['name', 'surname'] end end @@ -86,8 +86,8 @@ p = Printer.new(data) cols = p.send(:columns) - cols.length.should == 2 - cols.collect(&:name).sort.should == ['name', 'surname'] + expect(cols.length).to eq 2 + expect(cols.collect(&:name).sort).to eq ['name', 'surname'] end end @@ -97,8 +97,8 @@ p = Printer.new(Sandbox::Post.new, :except => :title) cols = p.send(:columns) - cols.length.should == 1 - cols.first.name.should == 'author' + expect(cols.length).to eq 1 + expect(cols.first.name).to eq 'author' end it "adds included columns" do @@ -107,9 +107,9 @@ p = Printer.new(Sandbox::Post.new, :include => :author) cols = p.send(:columns) - cols.length.should == 2 - cols.first.name.should == 'title' - cols.last.name.should == 'author' + expect(cols.length).to eq 2 + expect(cols.first.name).to eq 'title' + expect(cols.last.name).to eq 'author' end end end diff --git a/table_print.gemspec b/table_print.gemspec index 0feaa44..eb7736a 100644 --- a/table_print.gemspec +++ b/table_print.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |gem| gem.require_paths = ["lib"] gem.add_development_dependency 'cat', '~> 0.2.1' - gem.add_development_dependency 'cucumber', '~> 2.4.0' - gem.add_development_dependency 'rspec', '~> 2.11.0' - gem.add_development_dependency 'rake', '~> 0.9.2' + gem.add_development_dependency 'cucumber', '>= 7.1.0' + gem.add_development_dependency 'rspec', '~> 3.12.0' + gem.add_development_dependency 'rake', '~> 13.0' end