Skip to content

Instantly share code, notes, and snippets.

@baisa
Last active December 20, 2015 05:59
Show Gist options
  • Save baisa/6082486 to your computer and use it in GitHub Desktop.
Save baisa/6082486 to your computer and use it in GitHub Desktop.
class Temperature
def initialize (tempratures_hash)
@tempratures = tempratures_hash
end
def in_fahrenheit
puts @temperatures
@tempratures.key(:f) ? @tempratures[:f] : (@tempratures[:c] * 9.0 / 5) + 32
end
def in_celsius
@tempratures.key?(:c) ? @tempratures[:c] : (@tempratures[:f] - 32) * 5.0 / 9
end
end
basia@basia-Satellite-A200:~/code/ruby_tasks/temperature_object$ ^C
<erature_object$ rspec temperature_object_spec.rb:27
Run options: include {:locations=>{"./temperature_object_spec.rb"=>[27]}}
F
Failures:
1) Temperature can be constructed with an options hash in degrees fahrenheit at 50 degrees
Failure/Error: Temperature.new(:f => 50).in_fahrenheit.should == 50
NoMethodError:
undefined method `*' for nil:NilClass
# ./temperature.rb:10:in `in_fahrenheit'
# ./temperature_object_spec.rb:28:in `block (4 levels) in <top (required)>'
Finished in 0.0009 seconds
1 example, 1 failure
Failed examples:
rspec ./temperature_object_spec.rb:27 # Temperature can be constructed with an options hash in degrees fahrenheit at 50 degrees
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment