Commit c369ecbf by Aman Sharma

Added test cases on model recipe with factories

parent fa5c1a37
...@@ -54,6 +54,7 @@ end ...@@ -54,6 +54,7 @@ end
group :test do group :test do
gem 'factory_bot_rails' gem 'factory_bot_rails'
gem 'faker' gem 'faker'
gem 'capybara'
end end
......
...@@ -42,12 +42,22 @@ GEM ...@@ -42,12 +42,22 @@ GEM
i18n (>= 0.7, < 2) i18n (>= 0.7, < 2)
minitest (~> 5.1) minitest (~> 5.1)
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
arel (9.0.0) arel (9.0.0)
bindex (0.8.1) bindex (0.8.1)
bootsnap (1.4.8) bootsnap (1.4.8)
msgpack (~> 1.0) msgpack (~> 1.0)
builder (3.2.4) builder (3.2.4)
byebug (11.0.1) byebug (11.0.1)
capybara (3.15.1)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (~> 1.2)
xpath (~> 3.2)
concurrent-ruby (1.1.7) concurrent-ruby (1.1.7)
crass (1.0.6) crass (1.0.6)
diff-lcs (1.4.4) diff-lcs (1.4.4)
...@@ -88,6 +98,7 @@ GEM ...@@ -88,6 +98,7 @@ GEM
nokogiri (1.10.10) nokogiri (1.10.10)
mini_portile2 (~> 2.4.0) mini_portile2 (~> 2.4.0)
pg (1.2.3) pg (1.2.3)
public_suffix (4.0.6)
puma (3.12.6) puma (3.12.6)
rack (2.2.3) rack (2.2.3)
rack-proxy (0.6.5) rack-proxy (0.6.5)
...@@ -122,6 +133,7 @@ GEM ...@@ -122,6 +133,7 @@ GEM
rb-fsevent (0.10.4) rb-fsevent (0.10.4)
rb-inotify (0.10.1) rb-inotify (0.10.1)
ffi (~> 1.0) ffi (~> 1.0)
regexp_parser (1.8.1)
rspec-core (3.9.2) rspec-core (3.9.2)
rspec-support (~> 3.9.3) rspec-support (~> 3.9.3)
rspec-expectations (3.9.2) rspec-expectations (3.9.2)
...@@ -185,6 +197,8 @@ GEM ...@@ -185,6 +197,8 @@ GEM
websocket-driver (0.7.3) websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5) websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
PLATFORMS PLATFORMS
ruby ruby
...@@ -192,6 +206,7 @@ PLATFORMS ...@@ -192,6 +206,7 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
bootsnap (>= 1.1.0) bootsnap (>= 1.1.0)
byebug byebug
capybara
factory_bot_rails factory_bot_rails
faker faker
jbuilder (~> 2.5) jbuilder (~> 2.5)
......
FactoryBot.define do
factory :random_recipe, class: Recipe do
name { Faker::Food.dish }
ingredients { Faker::Food.ingredient }
instruction { Faker::Food.description }
end
end
require 'rails_helper' require 'rails_helper'
RSpec.describe Recipe do RSpec.describe Recipe, type: :model do
describe 'Recipe Model Validation Tests' do
it 'should run the first test case' do it 'should run the first test case' do
puts 'hello world! test' puts 'hello world! test'
expect('result').to eq('result') expect('result').to eq('result')
end end
let(:recipe) { build(:random_recipe) }
it 'should validate the data if name is nil' do
recipe.name = nil
expect(recipe.save).to eq(false)
end
it 'should validate the data if ingredients is nil' do
recipe.ingredients = nil
expect(recipe.save).to eq(false)
end
it 'should validate the data if instruction is nil' do
recipe.instruction = nil
expect(recipe.save).to eq(false)
end
end
end end
\ No newline at end of file
RSpec.configure do |config| RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods config.include FactoryBot::Syntax::Methods
end end
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment