Просмотр исходного кода

Add shoulda-matchers and test pokemon validation

Andrew Swistak 6 лет назад
Родитель
Сommit
d5ec6438b4
5 измененных файлов с 13 добавлено и 1 удалено
  1. 1 0
      Gemfile
  2. 3 0
      Gemfile.lock
  3. 1 0
      app/models/pokemon.rb
  4. 1 1
      spec/models/pokemon_spec.rb
  5. 7 0
      spec/rails_helper.rb

+ 1 - 0
Gemfile

@@ -36,6 +36,7 @@ group :development, :test do
   gem 'rails-controller-testing'
   gem 'rubocop', '~> 0.67.2', require: false
   gem 'rubocop-performance'
+  gem 'shoulda-matchers'
 
   # Using unreleased rspec version (since we're using Rails v6.0.0.beta3)
   # The following refs were the latest commits on their respective master

+ 3 - 0
Gemfile.lock

@@ -266,6 +266,8 @@ GEM
     selenium-webdriver (3.141.0)
       childprocess (~> 0.5)
       rubyzip (~> 1.2, >= 1.2.2)
+    shoulda-matchers (4.0.1)
+      activesupport (>= 4.2.0)
     spring (2.0.2)
       activesupport (>= 4.2)
     spring-watcher-listen (2.0.1)
@@ -339,6 +341,7 @@ DEPENDENCIES
   rubocop-performance
   sass-rails (~> 5.0)
   selenium-webdriver
+  shoulda-matchers
   spring
   spring-watcher-listen (~> 2.0.0)
   tzinfo-data

+ 1 - 0
app/models/pokemon.rb

@@ -1,4 +1,5 @@
 # frozen_string_literal: true
 
 class Pokemon < ApplicationRecord
+  validates :pokedex_number, presence: true
 end

+ 1 - 1
spec/models/pokemon_spec.rb

@@ -3,5 +3,5 @@
 require 'rails_helper'
 
 RSpec.describe Pokemon, type: :model do
-  # it {is_expected.to validate :pok}
+  it { is_expected.to validate_presence_of(:pokedex_number) }
 end

+ 7 - 0
spec/rails_helper.rb

@@ -82,3 +82,10 @@ RSpec.configure do |config|
     driven_by selenium_driver
   end
 end
+
+Shoulda::Matchers.configure do |config|
+  config.integrate do |with|
+    with.test_framework :rspec
+    with.library :rails
+  end
+end