Question
Ruby Current Program class BookInStock attr_reader :isbn attr_accessor :price #getters and setters are for the two variables are defined below def isbn #getter method for
Ruby
Current Program
class BookInStock attr_reader :isbn attr_accessor :price #getters and setters are for the two variables are defined below def isbn #getter method for isbn @isbn end
def isbn=(isbn) #setter method for isbn @isbn = isbn end
def price #getter method for price @price end
def price=(price) #setter method for price @price = Float(price) end
def initialize(isbn, price) raise ArgumentError if isbn.empty? || price
SPEC File for program is below
require 'rubybasics3.rb'
RSpec.configure do |config| config.filter_run_excluding :disabled => true end
describe "BookInStock" do it "should be defined" do expect { BookInStock }.not_to raise_error end
describe 'getters and setters' do before(:each) { @book = BookInStock.new('isbn1', 33.8) } it 'should set ISBN [10 points]' , points: 10 do expect(@book.isbn).to eq('isbn1') end it 'should set price [10 points]' , points: 10 do expect(@book.price).to eq(33.8) end it 'should be able to change ISBN [10 points]' , points: 10 do @book.isbn = 'isbn2' expect(@book.isbn).to eq('isbn2') end it 'should be able to change price [10 points]' , points: 10 do @book.price = 300.0 expect(@book.price).to eq(300.0) end end describe 'constructor', :disabled => true do it 'should reject invalid ISBN number [10 points]' , points: 10 do expect { BookInStock.new('', 25.00) }.to raise_error(ArgumentError) end it 'should reject zero price [10 points]' , points: 10 do expect { BookInStock.new('isbn1', 0) }.to raise_error(ArgumentError) end it 'should reject negative price [10 points]' , points: 10 do expect { BookInStock.new('isbn1', -5.0) }.to raise_error(ArgumentError) end end describe "#price_as_string", :disabled => true do it "should be defined" do expect(BookInStock.new('isbn1', 10)).to respond_to(:price_as_string) end it 'should display 33.95 as "$33.95" [10 points]' , points: 10 do expect(BookInStock.new('isbn11', 33.95).price_as_string).to eq('$33.95') end it "should display 1.1 as $1.10 [10 points]" , points: 10 do expect(BookInStock.new('isbn11', 1.1).price_as_string).to eq('$1.10') end it "should display 20 as $20.00 [10 points]" , points: 10 do expect(BookInStock.new('isbn11', 20).price_as_string).to eq('$20.00') end end end
Question5 2 pts Remove the,:disabled-true from the constructor collection in the spec/rubybasics3_spec.rb file. Don't forget to save your changes! Write code that will raise ArgumentError (one of Ruby's built-in exception types) if the ISBN number is the empty string or if the price is less than or equal to zero. Include the proper getters and setters for these attributes. Run rspec in the terminal window to test. Once everything is passing, upload your screenshot to this question. Note: You should see "8 examples, O failures". Upload Choose a File Capture.PNG has been removed. Question5 2 pts Remove the,:disabled-true from the constructor collection in the spec/rubybasics3_spec.rb file. Don't forget to save your changes! Write code that will raise ArgumentError (one of Ruby's built-in exception types) if the ISBN number is the empty string or if the price is less than or equal to zero. Include the proper getters and setters for these attributes. Run rspec in the terminal window to test. Once everything is passing, upload your screenshot to this question. Note: You should see "8 examples, O failures". Upload Choose a File Capture.PNG has been removedStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started