Skip to content

Instantly share code, notes, and snippets.

@maryannvalentine
Forked from reneedv/wine_glass.rb
Created June 13, 2012 07:09
Show Gist options
  • Save maryannvalentine/2922463 to your computer and use it in GitHub Desktop.
Save maryannvalentine/2922463 to your computer and use it in GitHub Desktop.
Wine Glass Homework 1
class WineGlass
attr_accessor :material, :volume, :stem_length, :wine_volume
def pretty_print_material
"Happy Dance Party : #{material}"
end
def pretty_print_stuff
"This wine glass is cool. It has a stem length of #{stem_length} and a volume of #{volume}ml"
end
def pretty_print_everything
"My #{material} wine glass, that has a stem length of #{stem_length}, is cool because it holds #{volume}ml"
end
def pretty_print_precise
"Needs More Wine :#{(wine_volume / volume) * 100}"
end
end
require 'minitest/autorun'
class TestWineGlass < MiniTest::Unit::TestCase
def setup
@wg = WineGlass.new
@wg.material = 'wood'
@wg.volume = 650
@wg.stem_length = 5
@wg.wine_volume = 65
end
def test_that_wine_glasses_have_volume
assert_respond_to @wg, :volume
end
def test_that_wg_has_a_pretty_print_for_material
@wg.material= 'wood'
assert_equal "Happy Dance Party : #{@wg.material}", @wg.pretty_print_material
end
def test_wg_pretty_prints_stem_length_and_volume
@wg.volume = 650
@wg.stem_length = 5
assert_equal "This wine glass is cool. It has a stem length of 5 and a volume of 650ml", @wg.pretty_print_stuff
end
def test_that_wg_has_everything
assert_equal "My wood wine glass, that has a stem length of 5, is cool because it holds 650ml", @wg.pretty_print_everything
end
def test_that_wg_needs_more_wine
@wg.volume= 650
@wg.wine_volume= 65
assert_equal "Needs More Wine :#{(@wg.wine_volume/ @wg.volume) * 100}", @wg.pretty_print_precise
end
end
@maryannvalentine
Copy link
Author

I'm stuck on this part with the following error message:

  1. Error:
    test_that_wg_needs_more_wine(TestWineGlass):
    NameError: undefined local variable or method wine_volume' for #<TestWineGlass:0x000001008e6a10> wine_glass.rb:89:intest_that_wg_needs_more_wine'

5 tests, 4 assertions, 0 failures, 1 errors, 0 skips
mary-ann-valentines-macbook-pro-7:~ maryannvalentine$

@maryannvalentine
Copy link
Author

Ok-I worked on it a little more, but I'm not seeing what I need to fix. Ideas?

  1. Failure:
    test_that_wg_needs_more_wine(TestWineGlass) [wine_glass.rb:89]:
    --- expected
    +++ actual
    @@ -1 +1 @@
    -"Needs More Wine : (@wg.wine_volume/ @wg.volume) * 100"
    +"Needs More Wine : (65 / 650 * 100)"

5 tests, 5 assertions, 1 failures, 0 errors, 0 skips
mary-ann-valentines-macbook-pro-7:~ maryannvalentine$

@maryannvalentine
Copy link
Author

and now...

  1. Failure:
    test_that_wg_needs_more_wine(TestWineGlass) [wine_glass.rb:89]:
    --- expected
    +++ actual
    @@ -1 +1 @@
    -"Needs More Wine : (@wg.wine_volume/ @wg.volume * 100)"
    +"Needs More Wine : (0)"

5 tests, 5 assertions, 1 failures, 0 errors, 0 skips
mary-ann-valentines-macbook-pro-7:~ maryannvalentine$

@maryannvalentine
Copy link
Author

yay! fixed it!
Run options: --seed 59338

Running tests:

.....

Finished tests in 0.000741s, 6747.6383 tests/s, 6747.6383 assertions/s.

5 tests, 5 assertions, 0 failures, 0 errors, 0 skips
mary-ann-valentines-macbook-pro-7:~ maryannvalentine$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment