Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

RUBY Code given dessert_rb class Dessert # add code for setters and getters def initialize(name, calories) # your code here end def healthy? # your

RUBYimage text in transcribed

Code given dessert_rb

class Dessert # add code for setters and getters def initialize(name, calories) # your code here end def healthy? # your code here end def delicious? # your code here end end

class JellyBean

_______________

code given for dessert_spec.rb

require 'dessert.rb' require 'byebug'

RSpec.configure do |config| config.filter_run_excluding :disabled => true end

describe Dessert do describe 'dessert getters and setters' do before(:each) { @dessert = Dessert.new('cake', 400) } it 'should set name [10 points]' , points: 10 do expect(@dessert.name).to eq('cake') end it 'should set calories [10 points]' , points: 10 do expect(@dessert.calories).to eq(400) end it 'should be able to change name [10 points]' , points: 10 do @dessert.name = 'ice cream' expect(@dessert.name).to eq('ice cream') end it 'should be able to change calories [10 points]' , points: 10 do @dessert.calories = 80 expect(@dessert.calories).to eq(80) end end describe 'delicious and healthy', :disabled => true do describe '-cake' do before :each do @dessert = Dessert.new('cake', 400) end it 'should be delicious [10 points]' do expect(@dessert).to be_delicious end it 'should not be healthy [10 points]' do expect(@dessert).not_to be_healthy end end describe '-apple' do before :each do @subject = Dessert.new('apple', 75) end it 'should be delicious [10 points]' do expect(@subject).to be_delicious end it 'should be healthy [10 points]' do expect(@subject).to be_healthy end end end end

describe JellyBean do describe 'JellyBean getters and setters', :disabled => true do before(:each) { @jellybean = JellyBean.new('vanilla') } it 'should contain 5 calories [2.5 points]' do expect(@jellybean.calories).to be == 5 end it 'should be named vanilla jelly bean [2.5 points]' do expect(@jellybean.name).to match(/vanilla jelly bean/i) end it 'should set flavor [2.5 points]' do expect(@jellybean.flavor).to eq('vanilla') end it 'should be able to change flavor [2.5 points]' do @jellybean.flavor = 'cherry' expect(@jellybean.flavor).to eq('cherry') end end describe 'modify delicious', :disabled => true do describe '-when non-licorice' do before :each do @jellybean = JellyBean.new('vanilla') end it 'should be delicious [5 points]' do expect(@jellybean).to be_delicious end end describe '-when licorice' do before :each do @jellybean = JellyBean.new('licorice') end it 'should not be delicious [5 points]' do expect(@jellybean).not_to be_delicious end end end end

____________________

My code for dessert.rb

class Dessert

def initialize(name, calories) @name = name @calories = calories end

def healthy? @calories

def delicious? true end end

class JellyBean

attr_accessor :flavor

def initialize(name, calories, flavor) super(name, calories) @name = name @calories = calories @flavor = flavor end

def delicious? if @flavor == "black licorice" false else true end end

end

Part 1 Create the getters and setters for name and calories in class Dessert. The constructor should accept arguments for name and calories. Run pe&in the terminal window to test. Once everything is passing, upload your screenshot to this question. Part 2 Remove the, :disabled-> true from the 'delicious and healthy' collection in the spec desset spesub file. Don't forget to save your changes! Define instance methods healthy?, which returns true if a dessert has less than 200 calories, and delicious?", which returns true for all desserts. Run pe&in the terminal window to test. Once everything is passing, upload your screenshot to this question. Part 3 Remove the, :disabled -> true from the 'LellvRean getters and setters' collection in the spec/ dessert specb file. Don't forget to save your changes! Create the getters and settings for the class JellyBean that inherits from Dessert. It should accept a single argument giving the jelly bean's flavor; a newly-created jelly bean should have 5 calories and its name should be the flavor plus "jelly bean", for example, "strawberry jelly bean" Run pe&in the terminal window to test. Once everything is passing, upload your screenshot to this question. Part 4 Remove the, :disabled-> true from the 'modify delicious' collection in the spec/ dessert specb file. Don't forget to save your changes! Modify delicious? to return false if the flavor is licorice, but true for all other flavors. The behavior of delicious? for non-jelly-bean desserts should be unchanged. Run pe&in the terminal window to test. Once everything is passing, upload your screenshot to this

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions

Question

An agreement to pay a supplier in the future is called an

Answered: 1 week ago