Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module UserTest
- def self.a_user_without_a_username_should_not_be_saved
- user = UserFixtures.user_without_username
- user.save
- errors = user.errors.messages
- return true if errors.to_s =~ /username/ && errors.to_s =~ /be blank/
- end
- def self.a_username_should_contain_at_least_8_characters
- user = UserFixtures.username_too_short
- user.save
- errors = user.errors.messages
- return true if errors.to_s =~ /username/ && errors.to_s =~ /6 characters/
- end
- end
- module UserFixtures
- def self.user_without_username
- User.new(email: Faker::Internet.email, password: 'abc123abc123')
- end
- def self.username_too_short
- User.new(email: Faker::Internet.email, password: 'abc123abc123', username: 'foo')
- end
- end
- def run_user_tests
- # To turn on logging again
- # old_logger = ActiveRecord::Base.logger
- # ActiveRecord::Base.logger = old_logger
- ActiveRecord::Base.logger = nil
- counter = 0
- # Use Faker for these tests
- UserTest.methods(false).each do |method_name|
- User.delete_all
- unless UserTest.send(method_name) == true
- puts "Failed: #{method_name}"
- counter += 1
- end
- end
- puts "All User tests passed." unless counter > 0
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement