spec/lib/percentable/percent_spec.rb in percentable-1.0.0 vs spec/lib/percentable/percent_spec.rb in percentable-1.0.1
- old
+ new
@@ -220,9 +220,30 @@
it 'should return the result of multipling the percent by the number' do
expect(percent * numeric).to eq subject.class.new(40)
end
end
+
+ context 'multiplying anything else' do
+ let(:other_thing) { double }
+ let(:percent) { subject.class.new(20) }
+
+ context 'responds to to_f' do
+ before { allow(other_thing).to receive(:to_f).and_return 1.0 }
+
+ it "should return the float value times the percent" do
+ expect(percent * other_thing).to eq subject.class.new(20)
+ end
+ end
+
+ context 'does not respond to to_f' do
+ before { allow(other_thing).to receive(:to_f).and_raise(NoMethodError) }
+
+ it "should raise a no method error" do
+ expect { percent * other_thing }.to raise_error(NoMethodError)
+ end
+ end
+ end
end
describe '#/' do
context 'dividing percents' do
let(:percent1) { subject.class.new(50) }