cypress-on-rails 1.8.1 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6bf2c478221a73bfd04c79925bfbda32188e6bad7bc95669df6dd5c0080a5431
4
- data.tar.gz: d7c0a2b7db03f4410b0fd2bccadc557b94cbbafa84f1a583eebe8614bbe7b114
3
+ metadata.gz: 3b8019daab6920154502f30e3a0bc5acb508d3e54cb7befe5274442b70724e02
4
+ data.tar.gz: 626901503a647087b14785b8d0df09c1033a01be4cf4f8456beeed376880f5a8
5
5
  SHA512:
6
- metadata.gz: 8accebdf65474c35fe2a26c7aed606d5a3d1da221024eb7569e12b5b0fb6802ac8063586aa34ce3564e969cbfea7bbcbd0c360e329b863f7f2dbaddc4d79fd3a
7
- data.tar.gz: 4bc6725bb7d1b3b9e1b5c7d698b399113191661623a21f95a58829ac0d825128767e4f565876ffcc7f6e55c77250595adfa9a109d01ba9ffae40b07933b82297
6
+ metadata.gz: 7379070d5df5642e4d9c45dcd3b935784278b409dde546dd9d8e334d54c473f5b3daf1b0061edc9dcabf2b15d3e1b0a6cf4fb9e75ce7d3bf2bf527f0af29dd85
7
+ data.tar.gz: 65dde5afa09ef3a862a19928cd76ead9c5f2755c4c15d22c3b978882ae58393ffbbe8799c4e1e6641301fcd20bb82342220029679443249bf8f1671b91c25c83
data/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ ## [1.11.0]
2
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.10.1...v1.11.0
3
+
4
+ ### Changed
5
+ * improve app command logging on cypress
6
+ * Allow build and build_list commands to be executed against factory bot [PR 87](https://github.com/shakacode/cypress-on-rails/pull/87) by [Alexander-Blair]
7
+
8
+ ## [1.10.1]
9
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.9.1...v1.10.1
10
+
11
+ ### Changed
12
+ * improve error message received from failed command
13
+
14
+ ## [1.9.1]
15
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.9.0...v1.9.1
16
+
17
+ ### Fixed
18
+ * fix using `load` in command files
19
+
20
+ ## [1.9.0]
21
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.8.1...v1.9.0
22
+
23
+ ### Changed
24
+ * Update default generated folder to cypress instead of spec/cypress
25
+ * Add a generator option to not install cypress
26
+ * generator by default does not include examples
27
+ * default on local to run cypress in development mode
28
+
1
29
  ## [1.8.1]
2
30
  [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.8.0...v1.8.1
3
31
 
data/README.md CHANGED
@@ -4,10 +4,19 @@
4
4
 
5
5
  ----
6
6
 
7
- This project is sponsored by the software consulting firm [ShakaCode](https://www.shakacode.com), creator of the [React on Rails Gem](https://github.com/shakacode/react_on_rails). We focus on React front-ends, often with Ruby on Rails or Gatsby. The best way to see what we do is to see the details of [our recent work](https://www.shakacode.com/recent-work). Feel free to engage in discussions around this gem at our [forum category for Cypress](https://forum.shakacode.com/c/cypress-on-rails/55).
7
+ This project is sponsored by the software consulting firm [ShakaCode](https://www.shakacode.com), creator of the [React on Rails Gem](https://github.com/shakacode/react_on_rails). We focus on React (with TS or ReScript) front-ends, often with Ruby on Rails or Gatsby. See [our recent work](https://www.shakacode.com/recent-work) and [client engagement model](https://www.shakacode.com/blog/client-engagement-model/). Feel free to engage in discussions around this gem at our [Slack Channel](https://join.slack.com/t/reactrails/shared_invite/enQtNjY3NTczMjczNzYxLTlmYjdiZmY3MTVlMzU2YWE0OWM0MzNiZDI0MzdkZGFiZTFkYTFkOGVjODBmOWEyYWQ3MzA2NGE1YWJjNmVlMGE) or our [forum category for Cypress](https://forum.shakacode.com/c/cypress-on-rails/55).
8
+
9
+ Interested in joining a small team that loves open source? Check our [careers page](https://www.shakacode.com/career/).
8
10
 
9
11
  ----
10
12
 
13
+ # Totally new to Cypress?
14
+ Suggest you first learn the basics of Cypress before attempting to integrate with Ruby on Rails
15
+
16
+ * [Good start Here](https://docs.cypress.io/examples/examples/tutorials.html#Best-Practices)
17
+
18
+ ## Overview
19
+
11
20
  Gem for using [cypress.io](http://github.com/cypress-io/) in Rails and ruby rack applications
12
21
  with the goal of controlling State as mentioned in [Cypress Best Practices](https://docs.cypress.io/guides/references/best-practices.html#Organizing-Tests-Logging-In-Controlling-State)
13
22
 
@@ -28,7 +37,7 @@ Has examples of setting up state with:
28
37
  * [Video of getting started with this gem](https://grant-ps.blog/2018/08/10/getting-started-with-cypress-io-and-ruby-on-rails/)
29
38
  * [Article: Introduction to Cypress on Rails](https://www.shakacode.com/blog/introduction-to-cypress-on-rails/)
30
39
 
31
- ## Getting started
40
+ ## Installation
32
41
 
33
42
  Add this to your Gemfile:
34
43
 
@@ -43,14 +52,14 @@ Generate the boilerplate code using:
43
52
  ```shell
44
53
  bin/rails g cypress_on_rails:install
45
54
 
46
- # if you have/want a different cypress folder (default is spec/cypress)
47
- bin/rails g cypress_on_rails:install --cypress_folder=test/cypress
55
+ # if you have/want a different cypress folder (default is cypress)
56
+ bin/rails g cypress_on_rails:install --cypress_folder=spec/cypress
48
57
 
49
58
  # if you want to install cypress with npm
50
59
  bin/rails g cypress_on_rails:install --install_cypress_with=npm
51
60
 
52
61
  # if you already have cypress installed globally
53
- bin/rails g cypress_on_rails:install --install_cypress_with=skip
62
+ bin/rails g cypress_on_rails:install --no-install-cypress
54
63
 
55
64
  # to update the generated files run
56
65
  bin/rails g cypress_on_rails:update
@@ -69,24 +78,57 @@ if you are not using factory_bot look at `spec/cypress/app_commands/factory_bot.
69
78
 
70
79
  Now you can create scenarios and commands that are plain ruby files that get loaded through middleware, the ruby sky is your limit.
71
80
 
81
+ ### Update your database.yml
82
+
83
+ When writing cypress test on your local it's recommended to start your server in development mode so that changes you
84
+ make are picked up without having to restart the server.
85
+ It's recommend you update your database.yml to check if the CYPRESS environment variable is set and switch it to the test database
86
+ otherwise cypress will keep clearing your development database.
87
+
88
+ for example:
89
+
90
+ ```yaml
91
+ development:
92
+ <<: *default
93
+ database: <%= ENV['CYPRESS'] ? 'my_db_test' : 'my_db_development' %>
94
+ test:
95
+ <<: *default
96
+ database: my_db_test
97
+ ```
98
+
72
99
  ### WARNING
73
100
  *WARNING!!:* cypress-on-rails can execute arbitrary ruby code
74
101
  Please use with extra caution if starting your local server on 0.0.0.0 or running the gem on a hosted server
75
102
 
76
103
  ## Usage
77
104
 
78
- Start the rails server in test mode and start cypress
105
+ Getting started on your local environment
79
106
 
80
107
  ```shell
81
108
  # start rails
82
- RAILS_ENV=test bin/rake db:create db:schema:load
83
- bin/rails server -e test -p 5017
109
+ CYPRESS=1 bin/rails server -p 5017
84
110
 
85
111
  # in separate window start cypress
112
+ yarn cypress open
113
+ # or for npm
114
+ node_modules/.bin/cypress open
115
+ # or if you changed the cypress folder to spec/cypress
86
116
  yarn cypress open --project ./spec
87
117
  ```
88
118
 
119
+ How to run cypress on CI
120
+
121
+ ```shell
122
+ # setup rails and start server in background
123
+ # ...
124
+
125
+ yarn run cypress run
126
+ # or for npm
127
+ node_modules/.bin/cypress run
128
+ ```
129
+
89
130
  ### Example of using factory bot
131
+
90
132
  You can run your [factory_bot](https://github.com/thoughtbot/factory_bot) directly as well
91
133
 
92
134
  ```ruby
@@ -124,6 +166,42 @@ describe('My First Test', function() {
124
166
  })
125
167
  ```
126
168
 
169
+ In some cases, using static Cypress fixtures may not provide sufficient flexibility when mocking HTTP response bodies - it's possible to use `FactoryBot.build` to generate Ruby hashes that can then be used as mock JSON responses:
170
+ ```ruby
171
+ FactoryBot.define do
172
+ factory :some_web_response, class: Hash do
173
+ initialize_with { attributes.deep_stringify_keys }
174
+
175
+ id { 123 }
176
+ name { 'Mr Blobby' }
177
+ occupation { 'Evil pink clown' }
178
+ end
179
+ end
180
+
181
+ FactoryBot.build(:some_web_response) => { 'id' => 123, 'name' => 'Mr Blobby', 'occupation' => 'Evil pink clown' }
182
+ ```
183
+
184
+ This can then be combined with Cypress mocks:
185
+ ```js
186
+ describe('My First Test', function() {
187
+ it('visit root', function() {
188
+ // This calls to the backend to generate the mocked response
189
+ cy.appFactories([
190
+ ['build', 'some_web_response', { name: 'Baby Blobby' }]
191
+ ]).then(([responseBody]) => {
192
+ cy.intercept('http://some-external-url.com/endpoint', {
193
+ body: responseBody
194
+ });
195
+
196
+ // Visit the application under test
197
+ cy.visit('/')
198
+ })
199
+
200
+ cy.contains("Hello World")
201
+ })
202
+ })
203
+ ```
204
+
127
205
  ### Example of loading rails test fixtures
128
206
  ```ruby
129
207
  # spec/cypress/app_commands/activerecord_fixtures.rb
@@ -3,7 +3,7 @@ require 'cypress_on_rails/configuration'
3
3
  module CypressOnRails
4
4
  # loads and evals the command files
5
5
  class CommandExecutor
6
- def self.load(file,command_options = nil)
6
+ def self.perform(file,command_options = nil)
7
7
  load_cypress_helper
8
8
  file_data = File.read(file)
9
9
  eval file_data, binding, file
@@ -56,15 +56,20 @@ module CypressOnRails
56
56
  missing_command = commands.find {|command| !@file.exists?(command.file_path) }
57
57
 
58
58
  if missing_command.nil?
59
- results = commands.map { |command| @command_executor.load(command.file_path, command.options) }
60
-
61
59
  begin
62
- output = results.to_json
63
- rescue NoMethodError
64
- output = {"message" => "Cannot convert to json"}.to_json
65
- end
60
+ results = commands.map { |command| @command_executor.perform(command.file_path, command.options) }
66
61
 
67
- [201, {'Content-Type' => 'application/json'}, [output]]
62
+ begin
63
+ output = results.to_json
64
+ rescue NoMethodError
65
+ output = {"message" => "Cannot convert to json"}.to_json
66
+ end
67
+
68
+ [201, {'Content-Type' => 'application/json'}, [output]]
69
+ rescue => e
70
+ output = {"message" => e.message, "class" => e.class.to_s}.to_json
71
+ [500, {'Content-Type' => 'application/json'}, [output]]
72
+ end
68
73
  else
69
74
  [404, {}, ["could not find command file: #{missing_command.file_path}"]]
70
75
  end
@@ -19,6 +19,14 @@ module CypressOnRails
19
19
  instance.create_list(*args)
20
20
  end
21
21
 
22
+ def self.build(*args)
23
+ instance.build(*args)
24
+ end
25
+
26
+ def self.build_list(*args)
27
+ instance.build_list(*args)
28
+ end
29
+
22
30
  # @return [Array]
23
31
  attr_accessor :factory
24
32
  attr_accessor :always_reload
@@ -51,6 +59,22 @@ module CypressOnRails
51
59
  factory.create_list(*args)
52
60
  end
53
61
 
62
+ def build(*options)
63
+ load_files
64
+ factory_name = options.shift
65
+ if options.last.is_a?(Hash)
66
+ args = options.pop
67
+ else
68
+ args = {}
69
+ end
70
+ factory.build(factory_name, *options.map(&:to_sym), args.symbolize_keys)
71
+ end
72
+
73
+ def build_list(*args)
74
+ load_files
75
+ factory.build_list(*args)
76
+ end
77
+
54
78
  private
55
79
 
56
80
  # @param [String,Array] arg
@@ -84,4 +108,4 @@ module CypressOnRails
84
108
  @always_reload || @latest_mtime.nil? || @latest_mtime < current_latest_mtime
85
109
  end
86
110
  end
87
- end
111
+ end
@@ -1,3 +1,3 @@
1
1
  module CypressOnRails
2
- VERSION = '1.8.1'
2
+ VERSION = '1.11.0'.freeze
3
3
  end
@@ -1,8 +1,9 @@
1
1
  module CypressOnRails
2
2
  class InstallGenerator < Rails::Generators::Base
3
- class_option :cypress_folder, type: :string, default: 'spec/cypress'
3
+ class_option :cypress_folder, type: :string, default: 'cypress'
4
+ class_option :install_cypress, type: :boolean, default: true
4
5
  class_option :install_cypress_with, type: :string, default: 'yarn'
5
- class_option :install_cypress_examples, type: :boolean, default: true
6
+ class_option :install_cypress_examples, type: :boolean, default: false
6
7
  source_root File.expand_path('../templates', __FILE__)
7
8
 
8
9
  def install_cypress
@@ -11,14 +12,16 @@ module CypressOnRails
11
12
  directories.pop
12
13
  install_dir = "#{Dir.pwd}/#{directories.join('/')}"
13
14
  command = nil
14
- if options.install_cypress_with == 'yarn'
15
- command = "yarn --cwd=#{install_dir} add cypress --dev"
16
- elsif options.install_cypress_with == 'npm'
17
- command = "cd #{install_dir}; npm install cypress --save-dev"
18
- end
19
- if command
20
- say command
21
- fail 'failed to install cypress' unless system(command)
15
+ if options.install_cypress
16
+ if options.install_cypress_with == 'yarn'
17
+ command = "yarn --cwd=#{install_dir} add cypress --dev"
18
+ elsif options.install_cypress_with == 'npm'
19
+ command = "cd #{install_dir}; npm install cypress --save-dev"
20
+ end
21
+ if command
22
+ say command
23
+ fail 'failed to install cypress' unless system(command)
24
+ end
22
25
  end
23
26
  if options.install_cypress_examples
24
27
  directory 'spec/cypress/integration/examples', "#{options.cypress_folder}/integration/examples"
@@ -43,19 +46,5 @@ module CypressOnRails
43
46
  "\nimport './on-rails'",
44
47
  after: 'import \'./commands\''
45
48
  end
46
-
47
-
48
- def update_test_rb
49
- if File.exist?('config/environments/test.rb')
50
- gsub_file 'config/environments/test.rb',
51
- 'config.cache_classes = true',
52
- 'config.cache_classes = ENV[\'CI\'].present?'
53
- end
54
- if File.exist?('spec/dummy/config/environments/test.rb')
55
- gsub_file 'spec/dummy/config/environments/test.rb',
56
- 'config.cache_classes = true',
57
- 'config.cache_classes = ENV[\'CI\'].present?'
58
- end
59
- end
60
49
  end
61
50
  end
@@ -3,7 +3,15 @@ if defined?(CypressOnRails)
3
3
  c.cypress_folder = File.expand_path("#{__dir__}/../../<%= options.cypress_folder %>")
4
4
  # WARNING!! CypressOnRails can execute arbitrary ruby code
5
5
  # please use with extra caution if enabling on hosted servers or starting your local server on 0.0.0.0
6
- c.use_middleware = Rails.env.test?
6
+ c.use_middleware = !Rails.env.production?
7
7
  c.logger = Rails.logger
8
8
  end
9
+
10
+ # # if you compile your asssets on CI
11
+ # if ENV['CYPRESS'].present? && ENV['CI'].present?
12
+ # Rails.application.configure do
13
+ # config.assets.compile = false
14
+ # config.assets.unknown_asset_fallback = false
15
+ # end
16
+ # end
9
17
  end
@@ -1,9 +1,14 @@
1
1
  # This is loaded once before the first command is executed
2
2
 
3
3
  begin
4
- require 'database_cleaner'
4
+ require 'database_cleaner-active_record'
5
5
  rescue LoadError => e
6
- puts e.message
6
+ puts e.message
7
+ begin
8
+ require 'database_cleaner'
9
+ rescue LoadError => e
10
+ puts e.message
11
+ end
7
12
  end
8
13
 
9
14
  begin
@@ -1,13 +1,19 @@
1
1
  // CypressOnRails: dont remove these command
2
2
  Cypress.Commands.add('appCommands', function (body) {
3
- cy.log("APP: " + JSON.stringify(body))
3
+ Object.keys(body).forEach(key => body[key] === undefined ? delete body[key] : {});
4
+ const log = Cypress.log({ name: "APP", message: body, autoEnd: false })
4
5
  return cy.request({
5
6
  method: 'POST',
6
7
  url: "/__cypress__/command",
7
8
  body: JSON.stringify(body),
8
- log: true,
9
- failOnStatusCode: true
9
+ log: false,
10
+ failOnStatusCode: false
10
11
  }).then((response) => {
12
+ log.end();
13
+ if (response.status !== 201) {
14
+ expect(response.body.message).to.be.empty
15
+ expect(response.status).to.be.equal(201)
16
+ }
11
17
  return response.body
12
18
  });
13
19
  });
@@ -1,12 +1,12 @@
1
1
  require 'cypress_on_rails/command_executor'
2
2
 
3
3
  RSpec.describe CypressOnRails::CommandExecutor do
4
- describe '.load' do
4
+ describe '.perform' do
5
5
  let(:folder) { "#{__dir__}/command_executor" }
6
6
  subject { described_class }
7
7
 
8
- def executor_load(*values)
9
- subject.load(*values)
8
+ def executor_perform(*values)
9
+ subject.perform(*values)
10
10
  end
11
11
 
12
12
  before do
@@ -15,18 +15,18 @@ RSpec.describe CypressOnRails::CommandExecutor do
15
15
  end
16
16
 
17
17
  it 'runs test command' do
18
- executor_load("#{folder}/test_command.rb")
18
+ executor_perform("#{folder}/test_command.rb")
19
19
  expect(DummyTest.values).to eq(%w(hello))
20
20
  end
21
21
 
22
22
  it 'runs test command twice' do
23
- executor_load("#{folder}/test_command.rb")
24
- executor_load("#{folder}/test_command.rb")
23
+ executor_perform("#{folder}/test_command.rb")
24
+ executor_perform("#{folder}/test_command.rb")
25
25
  expect(DummyTest.values).to eq(%w(hello hello))
26
26
  end
27
27
 
28
28
  it 'runs command with options' do
29
- executor_load("#{folder}/test_command_with_options.rb", 'my_string')
29
+ executor_perform("#{folder}/test_command_with_options.rb", 'my_string')
30
30
  expect(DummyTest.values).to eq(%w(my_string))
31
31
  end
32
32
  end
@@ -16,13 +16,13 @@ RSpec.describe CypressOnRails::Middleware do
16
16
 
17
17
  context '/__cypress__/command' do
18
18
  before do
19
- allow(command_executor).to receive(:load).and_return({ id: 1, title: 'some result' })
19
+ allow(command_executor).to receive(:perform).and_return({ id: 1, title: 'some result' })
20
20
  allow(file).to receive(:exists?)
21
21
  env['PATH_INFO'] = '/__cypress__/command'
22
22
  end
23
23
 
24
24
  it 'command file exists' do
25
- allow(command_executor).to receive(:load).and_return({ id: 1, title: 'some result' })
25
+ allow(command_executor).to receive(:perform).and_return({ id: 1, title: 'some result' })
26
26
  env['rack.input'] = rack_input(name: 'seed')
27
27
  allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
28
28
 
@@ -30,7 +30,7 @@ RSpec.describe CypressOnRails::Middleware do
30
30
  expect(response).to eq([201,
31
31
  {"Content-Type"=>"application/json"},
32
32
  ["[{\"id\":1,\"title\":\"some result\"}]"]])
33
- expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/seed.rb', nil)
33
+ expect(command_executor).to have_received(:perform).with('spec/cypress/app_commands/seed.rb', nil)
34
34
  end
35
35
  end
36
36
 
@@ -42,13 +42,13 @@ RSpec.describe CypressOnRails::Middleware do
42
42
  expect(response).to eq([201,
43
43
  {"Content-Type"=>"application/json"},
44
44
  ["[{\"id\":1,\"title\":\"some result\"}]"]])
45
- expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/seed.rb', ['my_options'])
45
+ expect(command_executor).to have_received(:perform).with('spec/cypress/app_commands/seed.rb', ['my_options'])
46
46
  end
47
47
  end
48
48
 
49
49
  it 'command file does not exists' do
50
50
  object = BasicObject.new
51
- allow(command_executor).to receive(:load).and_return(object)
51
+ allow(command_executor).to receive(:perform).and_return(object)
52
52
  env['rack.input'] = rack_input(name: 'seed')
53
53
  allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
54
54
 
@@ -56,7 +56,7 @@ RSpec.describe CypressOnRails::Middleware do
56
56
  expect(response).to eq([201,
57
57
  {"Content-Type"=>"application/json"},
58
58
  ["{\"message\":\"Cannot convert to json\"}"]])
59
- expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/seed.rb', nil)
59
+ expect(command_executor).to have_received(:perform).with('spec/cypress/app_commands/seed.rb', nil)
60
60
  end
61
61
  end
62
62
 
@@ -68,7 +68,7 @@ RSpec.describe CypressOnRails::Middleware do
68
68
  expect(response).to eq([201,
69
69
  {"Content-Type"=>"application/json"},
70
70
  ["[{\"id\":1,\"title\":\"some result\"}]"]])
71
- expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/seed.rb', nil)
71
+ expect(command_executor).to have_received(:perform).with('spec/cypress/app_commands/seed.rb', nil)
72
72
  end
73
73
  end
74
74
 
@@ -82,8 +82,8 @@ RSpec.describe CypressOnRails::Middleware do
82
82
  expect(response).to eq([201,
83
83
  {"Content-Type"=>"application/json"},
84
84
  ["[{\"id\":1,\"title\":\"some result\"},{\"id\":1,\"title\":\"some result\"}]"]])
85
- expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/load_user.rb', nil)
86
- expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/load_sample.rb', {'all' => 'true'})
85
+ expect(command_executor).to have_received(:perform).with('spec/cypress/app_commands/load_user.rb', nil)
86
+ expect(command_executor).to have_received(:perform).with('spec/cypress/app_commands/load_sample.rb', {'all' => 'true'})
87
87
  end
88
88
  end
89
89
 
@@ -94,7 +94,7 @@ RSpec.describe CypressOnRails::Middleware do
94
94
 
95
95
  aggregate_failures do
96
96
  expect(response).to eq([404, {}, ['could not find command file: spec/cypress/app_commands/load_sample.rb']])
97
- expect(command_executor).to_not have_received(:load)
97
+ expect(command_executor).to_not have_received(:perform)
98
98
  end
99
99
  end
100
100
  end
@@ -12,7 +12,7 @@ RSpec.describe CypressOnRails::SmartFactoryWrapper do
12
12
  let(:mtime_hash) { {'file1.rb' => time_now, 'file2.rb' => time_now } }
13
13
  let(:files) { %w(file1.rb file2.rb) }
14
14
  let(:factory_double) do
15
- class_double(FactoryBot, create: nil, create_list: nil, "definition_file_paths=": nil, reload: nil)
15
+ class_double(FactoryBot, create: nil, create_list: nil, build: nil, build_list: nil, "definition_file_paths=": nil, reload: nil)
16
16
  end
17
17
  let(:kernel_double) { class_double(Kernel, load: true) }
18
18
  let(:file_double) { FileSystemDummy.new(mtime_hash) }
@@ -67,6 +67,31 @@ RSpec.describe CypressOnRails::SmartFactoryWrapper do
67
67
  expect(factory_double).to have_received(:create_list).with(:note, 10)
68
68
  end
69
69
 
70
+ it 'delegates build to the factory' do
71
+ subject.build(:user)
72
+ expect(factory_double).to have_received(:build).with(:user, {})
73
+ end
74
+
75
+ it 'delegates build to the factory and symbolize keys' do
76
+ subject.build(:user, {'name' => "name"})
77
+ expect(factory_double).to have_received(:build).with(:user, {name: 'name'})
78
+ end
79
+
80
+ it 'delegates build to the factory and symbolize keys with trait' do
81
+ subject.build(:user, 'trait1', {'name' => "name"})
82
+ expect(factory_double).to have_received(:build).with(:user, :trait1, {name: 'name'})
83
+ end
84
+
85
+ it 'delegates build to the factory and symbolize keys with only trait' do
86
+ subject.build(:user, 'trait2')
87
+ expect(factory_double).to have_received(:build).with(:user, :trait2, {})
88
+ end
89
+
90
+ it 'delegates build_list to the factory' do
91
+ subject.build_list(:note, 10)
92
+ expect(factory_double).to have_received(:build_list).with(:note, 10)
93
+ end
94
+
70
95
  it 'wont load the files if they have not changed' do
71
96
  subject.create(:user)
72
97
  subject.create_list(:user, 2)
@@ -14,7 +14,7 @@ bundle --version
14
14
  bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle
15
15
 
16
16
  echo '-- cypress install'
17
- bundle exec ./bin/rails g cypress_on_rails:install --cypress_folder=cypress --install_cypress_with=npm --no-install-cypress-examples
17
+ bundle exec ./bin/rails g cypress_on_rails:install --install_cypress_with=npm
18
18
  rm -vf cypress/integration/rails_examples/advance_factory_bot_spec.js
19
19
 
20
20
  echo '-- start rails server'
@@ -14,7 +14,7 @@ bundle --version
14
14
  bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle
15
15
 
16
16
  echo '-- cypress install'
17
- bundle exec ./bin/rails g cypress_on_rails:install --no-install-cypress-examples
17
+ bundle exec ./bin/rails g cypress_on_rails:install --cypress_folder=spec/cypress
18
18
  rm -vf spec/cypress/integration/rails_examples/advance_factory_bot_spec.js
19
19
 
20
20
  echo '-- start rails server'
@@ -14,7 +14,8 @@ bundle --version
14
14
  bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle
15
15
 
16
16
  echo '-- migration'
17
- bin/rails db:migrate
17
+ bundle exec ./bin/rails db:drop || true
18
+ bundle exec ./bin/rails db:create db:migrate
18
19
 
19
20
  echo '-- cypress install'
20
21
  bundle exec ./bin/rails g cypress_on_rails:install --cypress_folder=test/cypress --no-install-cypress-examples
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cypress-on-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.1
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - miceportal team
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-02-07 00:00:00.000000000 Z
12
+ date: 2021-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -323,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
323
323
  - !ruby/object:Gem::Version
324
324
  version: '0'
325
325
  requirements: []
326
- rubygems_version: 3.2.8
326
+ rubygems_version: 3.2.25
327
327
  signing_key:
328
328
  specification_version: 4
329
329
  summary: Integrates cypress with rails or rack applications