Skip to content

Instantly share code, notes, and snippets.

@mikz
Created April 12, 2012 14:51
Show Gist options
  • Save mikz/2367868 to your computer and use it in GitHub Desktop.
Save mikz/2367868 to your computer and use it in GitHub Desktop.
class Example
attr_reader :value
def initialize(value)
@value = value
end
def truthy?
!!@value
end
def falsy?
not truthy?
end
end
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
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
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