Skip to content

Commit 9b0ac00

Browse files
committed
add specs for Plot destructive methods
1 parent e5d0923 commit 9b0ac00

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

spec/plot_spec.rb

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
end
8181
end
8282

83-
context 'modifying datasets' do
83+
context 'safe datasets update' do
8484
before do
8585
@plot_math = Plot.new(['sin(x)', title: 'Just a sin'])
8686
@dataset = Dataset.new('exp(-x)')
@@ -173,6 +173,40 @@
173173
end
174174
end
175175

176+
context 'destructive datasets update' do
177+
before :each do
178+
@plot = Plot.new('sin(x)')
179+
end
180+
181+
it 'should update datasets in the existing Plot' do
182+
expect(@plot.update_dataset!(lw: 3)).to equal(@plot)
183+
expect(@plot.datasets[0].lw).to eql(3)
184+
end
185+
186+
it 'should replace dataset in the existing Plot' do
187+
expect(@plot.replace_dataset!('exp(x)')).to equal(@plot)
188+
expect(@plot.datasets[0].data).to eql('exp(x)')
189+
@plot[0] = 'cos(x)'
190+
expect(@plot.datasets[0].data).to eql('cos(x)')
191+
end
192+
193+
it 'should add datasets to the existing Plot' do
194+
expect(@plot.add_dataset!('exp(x)')).to equal(@plot)
195+
expect(@plot.datasets[0].data).to eql('exp(x)')
196+
expect(@plot.datasets[1].data).to eql('sin(x)')
197+
end
198+
199+
it 'should remove dataset from the existing Plot' do
200+
@plot.add_dataset!(1, 'exp(x)', 'cos(x)')
201+
expect(@plot.datasets.size).to eql(3)
202+
expect(@plot.remove_dataset!).to equal(@plot)
203+
expect(@plot.datasets.size).to eql(2)
204+
expect(@plot.datasets[0].data).to eql('sin(x)')
205+
expect(@plot.datasets[1].data).to eql('exp(x)')
206+
expect(@plot.datasets[2]).to be nil
207+
end
208+
end
209+
176210
context '#to_iruby' do
177211
it 'should handle output to iRuby' do
178212
available_terminals = {

0 commit comments

Comments
 (0)