Question: This is what I'm getting CODE Given is below # Ruby Basics Part 3 class BookInStock # YOUR CODE HERE end What i have now

 This is what I'm getting CODE Given is below # Ruby

This is what I'm getting

Basics Part 3 class BookInStock # YOUR CODE HERE end What i

CODE Given is below

# Ruby Basics Part 3

class BookInStock # YOUR CODE HERE

end

What i have now

# Ruby Basics Part 3

class BookInStock # YOUR CODE HERE attr_reader :isbn attr_accessor :price

def initialize(isbn, price)

raise ArgumentError if isbn.empty? || price

@isbn = isbn

@price = Float(price) end end

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

Question 2 1 pts Define a class called BooklnStock which represents a book with an ISBN number variable nameisbn), and price of the book as a floating-point number (variable name->price), as attributes. Your first step is to create your getters and setters. Read A Beginner's Guide to Ruby Your second step is to create a constructor should accept the ISBN number (a string, since in real life ISBN numbers can begin with zero and can include hyphens) as the first argument and price as second argument. Read Ruby Constructors&for more information Run rspec in the terminal window to test. Once everything is passing, upload your screenshot to this question. Note: You should see "5 examples, O failures". AWS Cloud9 File Edit Find View Go Run Tools Window Support Preview Run Share Go to Anything (Ctrl-P) Gemfile x hashes_spec.rbrubybasics3.rb rubybasics3_spex x routes.rb x hashes.rb # Ruby Basics Part 3 3 class Book!nStoc 4 # YOUR CODE HERE lib 5 attr_reader :isbn 6 D Rakefile D README LABS 7 attr_accessor :price 8 9 def initialize(isbn, price) 10 11 raise Argument Error if isbn. empty ? Il price true) Failures: 1) BookInstock getters and setters should be able to change ISBN [1e points] ric # ./spec/rubybasics3-spec .rb:21:inblock (3 levels) n Finished in 8.8843 seconds (files took 8.88535 seconds to load) Failed examples: # BookInstock getters and setters should be able to change ISBN [10 points] 9:05 PM Question 2 1 pts Define a class called BooklnStock which represents a book with an ISBN number variable nameisbn), and price of the book as a floating-point number (variable name->price), as attributes. Your first step is to create your getters and setters. Read A Beginner's Guide to Ruby Your second step is to create a constructor should accept the ISBN number (a string, since in real life ISBN numbers can begin with zero and can include hyphens) as the first argument and price as second argument. Read Ruby Constructors&for more information Run rspec in the terminal window to test. Once everything is passing, upload your screenshot to this question. Note: You should see "5 examples, O failures". AWS Cloud9 File Edit Find View Go Run Tools Window Support Preview Run Share Go to Anything (Ctrl-P) Gemfile x hashes_spec.rbrubybasics3.rb rubybasics3_spex x routes.rb x hashes.rb # Ruby Basics Part 3 3 class Book!nStoc 4 # YOUR CODE HERE lib 5 attr_reader :isbn 6 D Rakefile D README LABS 7 attr_accessor :price 8 9 def initialize(isbn, price) 10 11 raise Argument Error if isbn. empty ? Il price true) Failures: 1) BookInstock getters and setters should be able to change ISBN [1e points] ric # ./spec/rubybasics3-spec .rb:21:inblock (3 levels) n Finished in 8.8843 seconds (files took 8.88535 seconds to load) Failed examples: # BookInstock getters and setters should be able to change ISBN [10 points] 9:05 PM

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!