Skip to content

Commit

Permalink
Add factory_bot
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesdeb committed Apr 4, 2020
1 parent 1e5c498 commit dd213c4
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ database.yml
/yarn-error.log
yarn-debug.log*
.yarn-integrity
/spec/examples.txt
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'rspec-rails'
gem 'shoulda-matchers'
gem 'factory_bot_rails'
end

group :development do
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ GEM
diff-lcs (1.3)
erubi (1.9.0)
execjs (2.7.0)
factory_bot (5.1.2)
activesupport (>= 4.2.0)
factory_bot_rails (5.1.1)
factory_bot (~> 5.1.0)
railties (>= 4.2.0)
ffi (1.12.2)
globalid (0.4.2)
activesupport (>= 4.2.0)
Expand Down Expand Up @@ -212,6 +217,7 @@ DEPENDENCIES
bootsnap (>= 1.4.2)
bootstrap (~> 4.4.1)
byebug
factory_bot_rails
jbuilder (~> 2.7)
jquery-rails
listen (>= 3.0.5, < 3.2)
Expand Down
6 changes: 4 additions & 2 deletions spec/examples.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
example_id | status | run_time |
--------------------------------------------- | ------- | --------------- |
./spec/models/text_sample_spec.rb[1:1:1] | passed | 0.00407 seconds |
./spec/models/text_sample_spec.rb[1:1:2] | passed | 0.00749 seconds |
./spec/models/text_sample_spec.rb[1:1:1] | passed | 0.02027 seconds |
./spec/models/text_sample_spec.rb[1:1:2] | passed | 0.0024 seconds |
./spec/models/text_sample_spec.rb[1:2:1] | passed | 0.03488 seconds |
./spec/models/text_sample_spec.rb[1:2:2] | pending | 0.00001 seconds |
./spec/models/word_chunk_spec.rb[1:1:1] | passed | 0.00441 seconds |
./spec/models/word_chunk_spec.rb[1:1:2] | passed | 0.00293 seconds |
./spec/models/word_chunk_spec.rb[1:1:3] | passed | 0.00311 seconds |
Expand Down
7 changes: 7 additions & 0 deletions spec/factories/text_sample.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This will guess the TextSample class
FactoryBot.define do
factory :text_sample_simple, class: TextSample do
description { 'Simple' }
text { 'The man in the mirror' }
end
end
6 changes: 6 additions & 0 deletions spec/models/text_sample_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
it { should validate_presence_of(:description) }
it { should validate_presence_of(:text) }
end

describe '#build_word_chunks' do
let(:text_sample){ create(:text_sample_simple) }
it 'counts word chunks'
it 'assigns the word chunks to this text sample'
end
end
3 changes: 2 additions & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../config/environment', __dir__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
require 'support/factory_bot'

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
Expand Down
5 changes: 5 additions & 0 deletions spec/support/factory_bot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
puts "ljksfdlkfjlkjsdlkfdklfj"

RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end

0 comments on commit dd213c4

Please sign in to comment.