Guest User

Untitled

a guest
Jan 21st, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.76 KB | None | 0 0
  1. bundle exec rspec spec/models/user_spec.rb
  2.  
  3. I get few failures:
  4.  
  5. Failures:
  6.  
  7. 1) User
  8. ←[31mFailure/Error:←[0m ←[31mit { should be_valid }←[0m
  9. ←[31mexpected valid? to return true, got false←[0m
  10. ←[36m # ./spec/models/user_spec.rb:31:in `block (2 levels) in <top (required
  11. )>'←[0m
  12.  
  13. 2) User when email format is valid should be valid
  14. ←[31mFailure/Error:←[0m ←[31m@user.should be_valid←[0m
  15. ←[31mexpected valid? to return true, got false←[0m
  16. ←[36m # ./spec/models/user_spec.rb:64:in `block (4 levels) in <top (required
  17. )>'←[0m
  18. ←[36m # ./spec/models/user_spec.rb:62:in `each'←[0m
  19. ←[36m # ./spec/models/user_spec.rb:62:in `block (3 levels) in <top (required
  20. )>'←[0m
  21.  
  22. 3) User return value of authenticate method with valid password
  23. ←[31mFailure/Error:←[0m ←[31mit { should == found_user.authenticate(@user.p
  24. assword) }←[0m
  25. ←[31mNoMethodError:←[0m
  26. ←[31mundefined method `authenticate' for nil:NilClass←[0m
  27. ←[36m # ./spec/models/user_spec.rb:99:in `block (4 levels) in <top (required
  28. )>'←[0m
  29.  
  30. 4) User return value of authenticate method with invalid password
  31. ←[31mFailure/Error:←[0m ←[31mlet(:user_for_invalid_password) { found_user.a
  32. authenticate("invalid") }←[0m
  33. ←[31mNoMethodError:←[0m
  34. ←[31mundefined method `authenticate' for nil:NilClass←[0m
  35. ←[36m # ./spec/models/user_spec.rb:103:in `block (4 levels) in <top (require
  36. d)>'←[0m
  37. ←[36m # ./spec/models/user_spec.rb:105:in `block (4 levels) in <top (require
  38. d)>'←[0m
  39.  
  40. 5) User return value of authenticate method with invalid password
  41. ←[31mFailure/Error:←[0m ←[31mlet(:user_for_invalid_password) { found_user.a
  42. uthenticate("invalid") }←[0m
  43. ←[31mNoMethodError:←[0m
  44. ←[31mundefined method `authenticate' for nil:NilClass←[0m
  45. ←[36m # ./spec/models/user_spec.rb:103:in `block (4 levels) in <top (require
  46. d)>'←[0m
  47. ←[36m # ./spec/models/user_spec.rb:106:in `block (4 levels) in <top (require
  48. d)>'←[0m
  49.  
  50. 6) User return value of authenticate method with valid password
  51. ←[31mFailure/Error:←[0m ←[31mit { should == found_user.authenticate(@user.e
  52. mail) }←[0m
  53. ←[31mNoMethodError:←[0m
  54. ←[31mundefined method `authenticate' for nil:NilClass←[0m
  55. ←[36m # ./spec/models/user_spec.rb:120:in `block (4 levels) in <top (require
  56. d)>'←[0m
  57.  
  58. 7) User return value of authenticate method with invalid password
  59. ←[31mFailure/Error:←[0m ←[31mlet(:user_for_invalid_password) { found_user.a
  60. uthenticate("invalid") }←[0m
  61. ←[31mNoMethodError:←[0m
  62. ←[31mundefined method `authenticate' for nil:NilClass←[0m
  63. ←[36m # ./spec/models/user_spec.rb:124:in `block (4 levels) in <top (require
  64. d)>'←[0m
  65. ←[36m # ./spec/models/user_spec.rb:126:in `block (4 levels) in <top (require
  66. d)>'←[0m
  67.  
  68. 8) User return value of authenticate method with invalid password
  69. ←[31mFailure/Error:←[0m ←[31mlet(:user_for_invalid_password) { found_user.a
  70. uthenticate("invalid") }←[0m
  71. ←[31mNoMethodError:←[0m
  72. ←[31mundefined method `authenticate' for nil:NilClass←[0m
  73. ←[36m # ./spec/models/user_spec.rb:124:in `block (4 levels) in <top (require
  74. d)>'←[0m
  75. ←[36m # ./spec/models/user_spec.rb:127:in `block (4 levels) in <top (require
  76. d)>'←[0m
  77.  
  78. 9) User with a password that's too short
  79. ←[31mFailure/Error:←[0m ←[31mit { should be_valid }←[0m
  80. ←[31mexpected valid? to return true, got false←[0m
  81. ←[36m # ./spec/models/user_spec.rb:112:in `block (3 levels) in <top (require
  82. d)>'←[0m
  83.  
  84. Finished in 8.5 seconds
  85. ←[31m23 examples, 9 failures←[0m
  86.  
  87. Failed examples:
  88.  
  89. ←[31mrspec ./spec/models/user_spec.rb:31←[0m ←[36m# User ←[0m
  90. ←[31mrspec ./spec/models/user_spec.rb:60←[0m ←[36m# User when email format is va
  91. lid should be valid←[0m
  92. ←[31mrspec ./spec/models/user_spec.rb:99←[0m ←[36m# User return value of authent
  93. icate method with valid password ←[0m
  94. ←[31mrspec ./spec/models/user_spec.rb:105←[0m ←[36m# User return value of authen
  95. ticate method with invalid password ←[0m
  96. ←[31mrspec ./spec/models/user_spec.rb:106←[0m ←[36m# User return value of authen
  97. ticate method with invalid password ←[0m
  98. ←[31mrspec ./spec/models/user_spec.rb:120←[0m ←[36m# User return value of authen
  99. ticate method with valid password ←[0m
  100. ←[31mrspec ./spec/models/user_spec.rb:126←[0m ←[36m# User return value of authen
  101. ticate method with invalid password ←[0m
  102. ←[31mrspec ./spec/models/user_spec.rb:127←[0m ←[36m# User return value of authen
  103. ticate method with invalid password ←[0m
  104. ←[31mrspec ./spec/models/user_spec.rb:112←[0m ←[36m# User with a password that's
  105. too short ←[0m
  106.  
  107. require 'spec_helper'
  108.  
  109. describe User do
  110.  
  111. before do
  112. @user = User.new(name: "Example User", email: "user@example.com",
  113. password: "foobar",
  114. password_confirmation: "foobar")
  115. end
  116.  
  117. subject { @user }
  118.  
  119. it { should respond_to(:name) }
  120. it { should respond_to(:email) }
  121. it { should respond_to(:password_digest) }
  122. it { should respond_to(:password) }
  123. it { should respond_to(:password_confirmation) }
  124. it { should respond_to(:authenticate) }
  125.  
  126. it { should be_valid }
  127.  
  128. describe "When name is not present" do
  129. before { @user.name = " " }
  130. it { should_not be_valid }
  131. end
  132.  
  133. describe "when email is not present" do
  134. before { @user.email = " " }
  135. it { should_not be_valid}
  136. end
  137.  
  138. describe "when name is too long" do
  139. before { @user.name = "a" * 51 }
  140. it { should_not be_valid }
  141. end
  142.  
  143. describe "when email format is invalid" do
  144. it "should be invalid" do
  145. addresses = %w[user@foo,com user_at_foo.org example.user@foo.
  146. foo@bar_baz.com foo@bar+baz.com]
  147. addresses.each do |invalid_address|
  148. @user.email = invalid_address
  149. @user.should_not be_valid
  150. end
  151. end
  152. end
  153.  
  154. describe "when email format is valid" do
  155. it "should be valid" do
  156. addresses = %w[user@foo.COM A_US-ER@f.b.org frst.lst@foo.jp
  157. a+b@baz.cn]
  158. addresses.each do |valid_address|
  159. @user.email = valid_address
  160. @user.should be_valid
  161. end
  162. end
  163. end
  164.  
  165. describe "when email addresses is already taken" do
  166. before do
  167. user_with_same_email = @user.dup
  168. user_with_same_email.email = @user.email.upcase
  169. user_with_same_email.save
  170. end
  171.  
  172. it { should_not be_valid }
  173. end
  174.  
  175. describe "when password is not present" do
  176. before { @user.password = @user.password_confirmation = " "}
  177. it { should_not be_valid }
  178. end
  179.  
  180. describe "when password doesn't match confirmation" do
  181. before { @user.password_confirmation = "mismatch" }
  182. it { should_not be_valid }
  183. end
  184.  
  185. describe "when password confirmation is nil" do
  186. before { @user.password_confirmation = nil }
  187. it { should_not be_valid }
  188. end
  189.  
  190. describe "return value of authenticate method" do
  191. before { @user.save }
  192. let(:found_user) { User.find_by_email(@user.email) }
  193.  
  194. describe "with valid password" do
  195. it { should == found_user.authenticate(@user.password) }
  196. end
  197.  
  198. describe "with invalid password" do
  199. let(:user_for_invalid_password) {
  200. found_user.authenticate("invalid") }
  201.  
  202. it { should_not == user_for_invalid_password }
  203. specify { user_for_invalid_password.should be_false }
  204. end
  205. end
  206.  
  207. describe "with a password that's too short" do
  208. before { @user.password = @user.password_confirmation = "a" * 5 }
  209. it { should be_valid }
  210. end
  211.  
  212. describe "return value of authenticate method" do
  213. before { @user.save }
  214. let(:found_user) { User.find_by_email(@user.email) }
  215.  
  216. describe "with valid password" do
  217. it { should == found_user.authenticate(@user.email) }
  218. end
  219.  
  220. describe "with invalid password" do
  221. let(:user_for_invalid_password) {
  222. found_user.authenticate("invalid") }
  223.  
  224. it { should_not == user_for_invalid_password }
  225. specify { user_for_invalid_password.should be_false }
  226. end
  227. end
  228. end
  229.  
  230. My user.rb model:
  231.  
  232. class User < ActiveRecord::Base
  233. attr_accessible :email, :name, :password, :password_confirmation
  234. has_secure_password
  235.  
  236. before_save { |user| user.email = email.downcase }
  237.  
  238. validates :name, presence: true, length: { maximum: 50 }
  239. VALID_EMAIL_REGEX = /A[w+-.]+@[a-zd-.]+.[a-z]+z/i
  240. validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness:
  241. { case_sensitive: false }
  242. validates :password, presence: true, length: { minimum: 6 }
  243. validates :password_confirmation, presence: true
  244.  
  245. end
  246.  
  247. VALID_EMAIL_REGEX = /A[w+-.]+@[a-zd-.]+.[a-z]+z/i
  248.  
  249. VALID_EMAIL_REGEX = /A[w+-.]+@[a-zd-.]+.[a-z]+z/i
  250.  
  251. describe "with a password that's too short" do
  252. before { @user.password = @user.password_confirmation = "a" * 5 }
  253. it { should be_invalid }
  254. end
  255.  
  256. describe "with a password that's too short" do
  257. before { @user.password = @user.password_confirmation = "a" * 5 }
  258. it { should be_valid }
  259. end
Add Comment
Please, Sign In to add comment