Skip to content

Instantly share code, notes, and snippets.

@RobAWilkinson
Created January 28, 2015 18:53
Show Gist options
  • Save RobAWilkinson/2356b8e93e6367d16c5e to your computer and use it in GitHub Desktop.
Save RobAWilkinson/2356b8e93e6367d16c5e to your computer and use it in GitHub Desktop.
Ninja_spec.rb
require 'rails_helper'
RSpec.describe Ninja, :type => :model do
let(:subject1) { Ninja.new(secret_name: "Joe") }
let(:subject2) { Ninja.new(name: "Akira")}
it "responds to name" do
expect(subject1).to respond_to(:name)
end
it "is invalid without a name" do
expect(subject1).to be_invalid
end
it "raises an error without a name" do
expect{ subject1.save! }.to raise_error(ActiveRecord::RecordInvalid)
end
it "responds to name" do
expect(subject2).to respond_to(:secret_name)
end
it "is invalid without a name" do
expect(subject2).to be_invalid
# subject2.valid?
end
it "raises an error without a name" do
expect{ subject2.save! }.to raise_error(ActiveRecord::RecordInvalid)
end
# Describe class method attack
describe ".attack" do
it "responds to attack" do
expect(Ninja).to respond_to(:attack)
end
end
# Describe instance method hide
describe "#hide" do
it "responds to hide" do
expect(subject1).to respond_to(:hide)
end
end
context 'When a ninja is created with the name of Ashley' do
let(:subject) { Ninja.new(name: "Ashley")}
it 'should start with two weapons' do
expect(subject.weapons).to be_a(Array)
expect(subject.weapons.count).to eq(2)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment