LoginSignup
0
0

More than 5 years have passed since last update.

Rspecの勉強02

Last updated at Posted at 2016-12-02

前回

Rspecの勉強01

参考サイト

はじめてのRSpec - まずテスト書いてからコード書くシンプルなチュートリアル

Rspecを身に付けるまでにすること

1、Rspec、TDDって何?
2、sampleコードを真似て書いてみる。コードの理解と雰囲気を掴む(参考サイトを参照)
3、自分で考えてRspecを書いてみる

OUT PUT(1〜2が目的)

はじめてのRSpec - まずテスト書いてからコード書くシンプルなチュートリアル

dog_spec.rb
equire "spec_helper"
require "dog"

describe Dog do
  it "is named 'Pochi'" do
    dog = Dog.new
    expect(dog.name).to eq 'Pochi'
  end

  it "has fangs" do
    dog = Dog.new
    expect(dog.fangs).to eq 2
  end

  it "is alived" do
    dog = Dog.new
    expect(dog).to be_alived
  end
end
dog.rb
class Dog
  attr_accessor :name, :fangs

  def initialize(name="Pochi")
    @name = name
    @fangs = 2
  end

  def alived?
    true
  end
end

次回

3を実施していく。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0