diff options
author | Matthew Lemon <y@yulqen.org> | 2023-12-20 17:15:29 +0000 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2023-12-20 17:15:29 +0000 |
commit | d5f5c3d7f2d92c180c56053c994a148afd63118a (patch) | |
tree | cab85e7cfc21e7a00e9719626e3db19789790f55 | |
parent | 17c866a3f93e24c5d022a3b9697a5c6293795f74 (diff) |
Adds factory_bot to rspec testing suite
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | Gemfile.lock | 6 | ||||
-rw-r--r-- | spec/factories/events.rb | 11 | ||||
-rw-r--r-- | spec/requests/events_spec.rb | 2 |
4 files changed, 19 insertions, 1 deletions
@@ -51,6 +51,7 @@ group :development, :test do # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem gem "debug", platforms: %i[ mri windows ] gem 'rspec-rails', '~> 6.1.0' + gem 'factory_bot_rails' end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index b621212..626a9db 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -106,6 +106,11 @@ GEM drb (2.2.0) ruby2_keywords erubi (1.12.0) + factory_bot (6.4.2) + activesupport (>= 5.0.0) + factory_bot_rails (6.4.2) + factory_bot (~> 6.4) + railties (>= 5.0.0) globalid (1.2.1) activesupport (>= 6.1) i18n (1.14.1) @@ -265,6 +270,7 @@ DEPENDENCIES capybara cssbundling-rails debug + factory_bot_rails jbuilder jsbundling-rails pry (~> 0.14.2) diff --git a/spec/factories/events.rb b/spec/factories/events.rb new file mode 100644 index 0000000..8fbba83 --- /dev/null +++ b/spec/factories/events.rb @@ -0,0 +1,11 @@ +FactoryBot.define do + factory :event do + name { "MyString" } + date { "2023-12-20" } + organisation + end + + factory :organisation do + name { "Smersh" } + end +end diff --git a/spec/requests/events_spec.rb b/spec/requests/events_spec.rb index f168576..96183ae 100644 --- a/spec/requests/events_spec.rb +++ b/spec/requests/events_spec.rb @@ -19,7 +19,7 @@ RSpec.describe "/events", type: :request do # adjust the attributes here as well. let(:valid_attributes) { # skip("Add a hash of attributes valid for your model") - { date: Date.new(2023, 1, 10), name: "Stunner", organisation_id: "2" } + build :event.attributes # build uses the factory and attributes converts to a hash.... } let(:invalid_attributes) { |