Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TDD will always be in your heart

TDD will always be in your heart

Niigata.rb #3 での発表資料です。

Kenichi Takahashi

August 31, 2013
Tweet

More Decks by Kenichi Takahashi

Other Decks in Programming

Transcript

  1. +6OJUͱग़ձ͏લ  ϓϩάϥϜΛॻ͘  NBJOΛॻ͘  ໨ࢹͰ֬ೝ͢Δ  ϓϩάϥϜΛͪΐͬͱมߋ͢Δ 

    ໨ࢹͰ֬ೝ͢Δ  ϓϩάϥϜΛ݁ߏมߋ͢Δ  NBJOΛॻ͖׵͑Δ  ໨ࢹͰ֬ೝ͢Δ  SZ
  2. describe SomeClass do context 'εςʔλείʔυ͕200' do context 'JSONͷϑΥʔϚοτ͕ਖ਼͍͠' do end

    context 'JSONͷϑΥʔϚοτ͕ෆਖ਼' do end end context 'εςʔλείʔυ͕4XX' do end context 'εςʔλείʔυ͕5XX' do context 'ϦτϥΠͯ͠੒ޭ͢Δ' do end context 'ϦτϥΠͯ͠΋5XX' do end end end ςετʹͯ͠ΈΔ
  3. ςετΛॻ͘ describe '.valid?' do context 'valid version string' do subject

    { JavaVersion.valid?('JDK7u40') } it { should be_true } end context 'invalid version string' do subject { JavaVersion.valid?('hoge') } it { should be_false } end end
  4. ςετΛॻ͘ describe '.parse' do context 'valid version string' do subject

    { JavaVersion.parse('JDK7u40') } it { should be } end context 'invalid version string' do it { expect { JavaVersion.parse('hoge') }.to raise_error } end end
  5. ϓϩμΫτίʔυΛॻ͘ class JavaVersion VERSION_FORMAT = /^JDK(\d)+u(\d+)$/ def self.valid?(str) str =~

    VERSION_FORMAT end def self.parse(str) raise "Invalid Version Format: #{str}" unless valid?(str) self.new(str) end def initialize(version_string) @version_string = version_string end def family_number @version_string =~ VERSION_FORMAT $1.to_i end end
  6. Ұาཱͪࢭ·Δ class JavaVersion VERSION_FORMAT = /^JDK(\d)+u(\d+)$/ def self.valid?(str) str =~

    VERSION_FORMAT end def self.parse(str) raise "Invalid Version Format: #{str}" unless valid?(str) self.new(str) end def initialize(version_string) @version_string = version_string end def family_number @version_string =~ VERSION_FORMAT $1.to_i end def update_number @version_string =~ VERSION_FORMAT $2.to_i end end Ϋϥεϝιου͕ ͔̎ͭʜ ॏෳʜ
  7. ϦϑΝΫλϦϯά class JavaVersion VERSION_FORMAT = /^JDK(\d)+u(\d+)$/ attr_reader :family_number, :update_number class

    << self def valid?(str) str =~ VERSION_FORMAT end def parse(str) raise "Invalid Version Format: #{str}" unless valid?(str) self.new(str) end end def initialize(version_string) version_string =~ VERSION_FORMAT @family_number = $1.to_i @update_number = $2.to_i end end
  8. ςετΛॻ͘ describe '#<=>' do let(:v7u40) { JavaVersion.parse('JDK7u40') } let(:v7u51) {

    JavaVersion.parse('JDK7u51') } let(:v8u0) { JavaVersion.parse('JDK8u0') } context 'compare update number' do it { v7u40.should be < v7u51 } end context 'compare family number' do it { v7u40.should be < v8u0 } end end
  9. ϓϩμΫτίʔυΛॻ͘ class JavaVersion include Comparable ... def <=>(target) if (self.family_number

    <=> target.family_number).zero? self.update_number <=> target.update_number else self.family_number <=> target.family_number end end end