Skip to content

Commit b0b4bce

Browse files
committed
use create! in simple model factory
1 parent 7c04b2e commit b0b4bce

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1+
require 'active_support/core_ext/string'
2+
13
module CypressDev
24
module SimpleRailsFactory
35
def self.create(type, params = {})
4-
type.camelize.constantize.create(params)
5-
rescue NameError => e
6-
Rails.logger.warn e.message
6+
type.camelize.constantize.create!(params)
77
end
88

99
def self.create_list(type, amount, params = {})
1010
amount.to_i.times do
1111
create(type,params)
1212
end
13-
rescue NameError => e
14-
Rails.logger.warn e.message
1513
end
1614
end
1715
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'cypress_dev/simple_rails_factory'
2+
3+
RSpec.describe CypressDev::SimpleRailsFactory do
4+
subject { CypressDev::SimpleRailsFactory }
5+
6+
class AppRecord
7+
def self.create!(*)
8+
end
9+
end
10+
11+
before { allow(AppRecord).to receive(:create!) }
12+
13+
it do
14+
subject.create('AppRecord', { my_args: 'Hello World' })
15+
16+
expect(AppRecord).to have_received(:create!).with( { my_args: 'Hello World' } )
17+
end
18+
19+
it do
20+
expect{ subject.create('UnknownRecord', { my_args: 'Hello World' }) }.
21+
to raise_error(NameError)
22+
end
23+
end

0 commit comments

Comments
 (0)