サンプルクラス
person.rb
class Person
attr_accessor :name
def initialize
@name = "kure"
end
end
class Person2
attr_accessor :name
def initialize
@name = "kure2"
end
end
サンプルRSpec
require 'person'
RSpec.describe Person do
subject(:kure){ Person.new }
# ★described_class で describeで宣言されたクラス(=Person)を取ってくる
subject(:kure_by_described_class){ described_class.new }
subject{ Person2.new }
# オーソドックスな書き方
it "name is kure" do
person = Person.new
expect(person.name).to eq("kure")
end
it "name is kure(described_class)" do
expect(kure_by_described_class.name).to eq("kure")
end
it "name is kure(subject)" do
expect(kure.name).to eq("kure")
end
it "name is kure2(subject)" do
expect(subject.name).to eq("kure2")
end
end