Created
April 12, 2012 14:51
-
-
Save mikz/2367868 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Example | |
attr_reader :value | |
def initialize(value) | |
@value = value | |
end | |
def truthy? | |
!!@value | |
end | |
def falsy? | |
not truthy? | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'example' | |
describe Example do | |
let(:value) { "value" } | |
subject { Example.new(value) } | |
it "should have value of the value" do | |
subject.value.should == value | |
end | |
its(:truthy?) { should be } | |
its(:falsy?) { should_not be } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/autorun' | |
require_relative 'example' | |
# Specifikace | |
describe Example, "example with value" do | |
let(:value) { "value" } | |
subject { Example.new(value) } | |
describe "when asked about the value" do | |
it "should be the value" do | |
subject.value.must_equal value | |
end | |
end | |
it "should be truthy" do | |
subject.truthy?.must_equal true | |
end | |
it "should not be falsy" do | |
subject.falsy?.wont_equal true | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/autorun' | |
require_relative 'example' | |
# Unit test | |
class TestExample < MiniTest::Unit::TestCase | |
def setup | |
@value = "value" | |
@example = Example.new(@value) | |
end | |
def test_value_will_return_value | |
assert_equal @value, @example.value | |
end | |
def test_it_is_truthy | |
assert @example.truthy? | |
end | |
def test_it_isnt_falsy | |
refute @example.falsy? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment