· 7 years ago · Aug 24, 2018, 11:22 PM
1RSPEC Test Passing that should fail
2require 'spec_helper'
3
4 describe User do
5 before(:each) do
6 @attr = { :email => "testuser@example.com", :password => "password", :password_confirmation => "password" }
7 end
8
9
10 it "should reject emails that are too long" do
11 long_email = "a" * 101 + "gmail.com"
12 long_email = User.new (@attr.merge(:email => long_email))
13 long_email.should_not be_valid
14 end
15
16class User < ActiveRecord::Base
17 authenticates_with_sorcery!
18
19 attr_accessible :email, :password, :password_confirmation
20
21 validates_presence_of :password, :on => :create
22 validates :password, :confirmation => true,
23 :length => { :within => 6..100 }
24
25 email_regex = /A[w+-.]+@[a-zd-.]+.[a-z]+z/i
26 validates :email, :presence => true,
27 :format => { :with => email_regex },
28 :uniqueness => {:case_sensitive => false},
29 :length => { :within => 5..100 }
30end
31
32require 'spec_helper'
33
34describe User do
35 let(:attr){
36 {:email => "testuser@example.com", :password => "password", :password_confirmation => "password" }
37 }
38
39 context "When given an email address" do
40 context "That is too long" do
41 let(:long_email){ "a" * 101 + "gmail.com" }
42 subject{ User.new attr.merge(:email => long_email) }
43
44 specify{ subject.should_not be_valid }
45 end
46 context "That is too short" do
47 pending
48 end
49 context "That is between 5 and 100 characters long"
50 pending
51 end
52 end
53
54end