Created
July 31, 2015 12:17
-
-
Save gin0606/03d138447348a49ff65b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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