Skip to content

Instantly share code, notes, and snippets.

@gin0606
Created July 31, 2015 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gin0606/03d138447348a49ff65b to your computer and use it in GitHub Desktop.
Save gin0606/03d138447348a49ff65b to your computer and use it in GitHub Desktop.
RSpec.describe User do
context "with correct parameters" do
subject { build(:user) }
it { is_expected.to be_valid }
end
describe "User has properties" do
subject { build(:user) }
it { is_expected.to respond_to :screen_name }
it { is_expected.to respond_to :name }
it { is_expected.to respond_to :password_digest }
it { is_expected.to respond_to :password }
it { is_expected.to respond_to :password_confirmation }
end
describe '.screen_name' do
let(:user) { build(:user) }
subject { user }
context "with blank" do
before { user.screen_name = " " }
it { is_expected.not_to be_valid }
end
context "with 15 characters" do
before { user.screen_name = "c" * 15 }
it { is_expected.to be_valid }
end
context "with exceeds 15 characters" do
before { user.screen_name = "c" * 16 }
it { is_expected.not_to be_valid }
end
context "when exist same screen_name user" do
before {
user_with_same_screen_name = user.dup
user_with_same_screen_name.save
}
it { is_expected.not_to be_valid }
end
context "with exist same UPCASE screen_name user" do
before {
user_with_same_screen_name = user.dup
user_with_same_screen_name.screen_name = user.screen_name.upcase
user_with_same_screen_name.save
}
it { is_expected.not_to be_valid }
end
end
context "when name is not present" do
subject { build(:user, name: "") }
it { is_expected.not_to be_valid }
end
describe '.password' do
context "with blank" do
let(:user) { build(:user, password: " ") }
subject { user }
it { is_expected.not_to be_valid }
end
end
describe '.password_confirmation' do
let(:user) { build(:user) }
subject { user }
context "with wrong password_confirmation" do
before { user.password_confirmation = "mismatch password" }
it { is_expected.not_to be_valid }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment