Skip to content

Commit

Permalink
Merge pull request #77 from SciRuby/test_improve
Browse files Browse the repository at this point in the history
Improving the coverage report for view.rb file
  • Loading branch information
Shekharrajak authored Feb 18, 2018
2 parents aa10d05 + 22f8578 commit 3bc9e6c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
1 change: 0 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ AllCops:
Include:
- 'lib/**/*'
Exclude:
# - 'daru-view.gemspec'
- 'Rakefile'
- 'Gemfile'
- 'Guardfile'
Expand Down
8 changes: 3 additions & 5 deletions lib/daru/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,14 @@ def table_library=(lib)
case lib
when :googlecharts
# plot chart and table drawing
@plotting_library = lib
Daru::View::Plot.adapter = lib
Daru::View::Table.adapter = lib
@plotting_library = @table_library = lib
Daru::View::Plot.adapter = Daru::View::Table.adapter = lib
when :datatables
# only for table drawing
Daru::View::Table.adapter = lib
@table_library = Daru::View::Table.adapter = lib
else
raise ArgumentError, "Unsupported library #{lib}"
end

# When code is running in console/terminal then IRuby NameError.
# Since IRuby methods can't work in console.
begin
Expand Down
6 changes: 5 additions & 1 deletion spec/plot_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
let(:plot_df) { Daru::View::Plot.new(df, type: :line, x: :a, y: :c) }
let(:plot_dv) { Daru::View::Plot.new(dv, type: :line) }
context 'initialize' do
before { Daru::View.plotting_library = :nyaplot }
# before { Daru::View.plotting_library = :nyaplot }
context 'Default plotting_library is nyaplot' do
it { expect(Daru::View.plotting_library).to eq(:nyaplot)}
end

context 'chart using DataFrame' do
it { expect(plot_df).to be_a Daru::View::Plot }
it { expect(plot_df.chart.class).to eq Nyaplot::Plot }
Expand Down
47 changes: 47 additions & 0 deletions spec/view_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
describe Daru::View, "Daru::View class basic methods" do
context "#plotting_library" do
context 'Set plotting library to googlecharts' do
before { Daru::View.plotting_library = :googlecharts}
it { expect(Daru::View.plotting_library).to eq(:googlecharts) }
end

context 'Set plotting library to highcharts' do
before { Daru::View.plotting_library = :highcharts}
it { expect(Daru::View.plotting_library).to eq(:highcharts) }
end

context 'Set plotting library to nyaplot' do
before { Daru::View.plotting_library = :nyaplot}
it { expect(Daru::View.plotting_library).to eq(:nyaplot) }
end

context 'Set plotting library to xyz, which is unsupported' do
it "should raise ArgumentError" do
expect{
Daru::View.plotting_library = :xyz_library
}.to raise_error(ArgumentError)
end
end
end

context "#table_library" do
context 'Set table library to googlecharts' do
before { Daru::View.table_library = :googlecharts}
it { expect(Daru::View.table_library).to eq(:googlecharts) }
end

context 'Set table library to datatables' do
before { Daru::View.table_library = :datatables}
it { expect(Daru::View.table_library).to eq(:datatables) }
end

context 'Set table library to xyz, which is unsupported' do
it "should raise ArgumentError" do
expect{
Daru::View.table_library = :xyz_library
}.to raise_error(ArgumentError)
end
end
end

end

0 comments on commit 3bc9e6c

Please sign in to comment.