cypress-on-rails 1.9.1 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df550a0ca15f4fe35c0bdf3227596ea79e6cbb9c407117592383466c81f45447
4
- data.tar.gz: 6dc7c397f9e13dd6ad7f60e5d0bb929bb1aa0a65dab9ed5992f1d260686316ba
3
+ metadata.gz: 32a416c65647445473bce7bcf306bda04eafb673d8d4af20c795f13692f4da8e
4
+ data.tar.gz: ee456e7396cfa0d94cc9cd80d0a54dc6c89248254c3855b66578f8e214a0982d
5
5
  SHA512:
6
- metadata.gz: cd12f10387af1cd51f91e65acea0b2705970487e101fe963273a70982c0f789a00896bab78ea461a2fee1dab3e1aa63be8d0e9d45e8ab39b8bee7b0c3821a5cb
7
- data.tar.gz: dbf5569c5d5b71bd737b28f656f2c9993a0235ebc9e87c8f42def465521900c713fa9ffe33035b5603d00796c7c6bae39941e36f261b17266159567addf470ff
6
+ metadata.gz: 4022aeb303bf3fa6514cd2b221869bb531e7e0be1b85de8f35ba20f6e5d2ff9fc8062ab2560a7d71d17ce0931719c3e57a33b23b25e3fa3ddb60a02de579c527
7
+ data.tar.gz: 18d9b6423eb5fafbf2bf756de4b9e72fc8a5dc8b0240a15a1598e97f16acac6e589ff591493158ced0779374a27a347525c75eb4b4d1b9b2dd16364276afd10d
@@ -0,0 +1,57 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ rails_3_2:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: 2.3
19
+ bundler-cache: true
20
+ - name: Run tests
21
+ run: bundle exec rake
22
+ - run: gem uninstall -v '>= 2' -ax bundler || true
23
+ - run: gem install bundler -v '< 2'
24
+ - name: Run interaction tests
25
+ run: ./spec/integrations/rails_3_2/test.sh
26
+
27
+ rails_4_2:
28
+ runs-on: ubuntu-latest
29
+
30
+ steps:
31
+ - uses: actions/checkout@v2
32
+ - name: Set up Ruby
33
+ uses: ruby/setup-ruby@v1
34
+ with:
35
+ ruby-version: 2.5
36
+ bundler-cache: true
37
+ - name: Run tests
38
+ run: bundle exec rake
39
+ - run: gem uninstall -v '>= 2' -ax bundler || true
40
+ - run: gem install bundler -v '< 2'
41
+ - name: Run interaction tests
42
+ run: ./spec/integrations/rails_4_2/test.sh
43
+
44
+ rails_5_2:
45
+ runs-on: ubuntu-latest
46
+
47
+ steps:
48
+ - uses: actions/checkout@v2
49
+ - name: Set up Ruby
50
+ uses: ruby/setup-ruby@v1
51
+ with:
52
+ ruby-version: 2.6
53
+ bundler-cache: true
54
+ - name: Run tests
55
+ run: bundle exec rake
56
+ - name: Run interaction tests
57
+ run: ./spec/integrations/rails_5_2/test.sh
data/.gitignore CHANGED
@@ -5,4 +5,5 @@ spec/examples.txt
5
5
  .idea
6
6
  spec/test.log
7
7
  pkg/*.gem
8
- vendor/bundle
8
+ vendor/bundle
9
+ .vscode
data/CHANGELOG.md CHANGED
@@ -1,3 +1,35 @@
1
+ ## [1.12.1]
2
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.12.0...v1.12.1
3
+
4
+ ### Tasks
5
+ * Documenting how to setup Factory Associations [PR 100](https://github.com/shakacode/cypress-on-rails/pull/100)
6
+
7
+ ### Fixed
8
+ * keep track of factory manual reloads to prevent auto_reload from reloading again [PR 98](https://github.com/shakacode/cypress-on-rails/pull/98)
9
+
10
+ ## [1.12.0]
11
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.11.0...v1.12.0
12
+
13
+ ### Changed
14
+ * only reload factories on clean instead of every factory create request [PR 95](https://github.com/shakacode/cypress-on-rails/pull/95)
15
+ * alternative command added for get tail of logs [PR 89](https://github.com/shakacode/cypress-on-rails/pull/89) by [ccrockett]
16
+
17
+ ### Tasks
18
+ * switch from travis to github actions [PR 96]
19
+
20
+ ## [1.11.0]
21
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.10.1...v1.11.0
22
+
23
+ ### Changed
24
+ * improve app command logging on cypress
25
+ * 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]
26
+
27
+ ## [1.10.1]
28
+ [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.9.1...v1.10.1
29
+
30
+ ### Changed
31
+ * improve error message received from failed command
32
+
1
33
  ## [1.9.1]
2
34
  [Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.9.0...v1.9.1
3
35
 
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # CypressOnRails
2
2
 
3
- [![Build Status](https://travis-ci.com/shakacode/cypress-on-rails.svg?branch=master)](https://travis-ci.org/shakacode/cypress-on-rails) [![Gem Version](https://badge.fury.io/rb/cypress-on-rails.svg)](https://badge.fury.io/rb/cypress-on-rails)
3
+ ![Build Status](https://github.com/shakacode/cypress-on-rails/actions/workflows/ruby.yml/badge.svg)
4
+ [![Gem Version](https://badge.fury.io/rb/cypress-on-rails.svg)](https://badge.fury.io/rb/cypress-on-rails)
4
5
 
5
6
  ----
6
7
 
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).
8
+ 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).
9
+
10
+ Interested in joining a small team that loves open source? Check our [careers page](https://www.shakacode.com/career/).
8
11
 
9
12
  ----
10
13
 
@@ -129,17 +132,6 @@ node_modules/.bin/cypress run
129
132
 
130
133
  You can run your [factory_bot](https://github.com/thoughtbot/factory_bot) directly as well
131
134
 
132
- ```ruby
133
- # spec/cypress/app_commands/factory_bot.rb
134
- require 'cypress_on_rails/smart_factory_wrapper'
135
-
136
- CypressOnRails::SmartFactoryWrapper.configure(
137
- always_reload: !Rails.configuration.cache_classes,
138
- factory: FactoryBot,
139
- files: Dir['./spec/factories/**/*.rb']
140
- )
141
- ```
142
-
143
135
  ```js
144
136
  // spec/cypress/integrations/simple_spec.js
145
137
  describe('My First Test', function() {
@@ -163,6 +155,43 @@ describe('My First Test', function() {
163
155
  })
164
156
  })
165
157
  ```
158
+ You can check the [association Docs](https://github.com/shakacode/cypress-on-rails/blob/master/docs/factory_bot_associations.md) on more ways to setup association with the correct data.
159
+
160
+ 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:
161
+ ```ruby
162
+ FactoryBot.define do
163
+ factory :some_web_response, class: Hash do
164
+ initialize_with { attributes.deep_stringify_keys }
165
+
166
+ id { 123 }
167
+ name { 'Mr Blobby' }
168
+ occupation { 'Evil pink clown' }
169
+ end
170
+ end
171
+
172
+ FactoryBot.build(:some_web_response) => { 'id' => 123, 'name' => 'Mr Blobby', 'occupation' => 'Evil pink clown' }
173
+ ```
174
+
175
+ This can then be combined with Cypress mocks:
176
+ ```js
177
+ describe('My First Test', function() {
178
+ it('visit root', function() {
179
+ // This calls to the backend to generate the mocked response
180
+ cy.appFactories([
181
+ ['build', 'some_web_response', { name: 'Baby Blobby' }]
182
+ ]).then(([responseBody]) => {
183
+ cy.intercept('http://some-external-url.com/endpoint', {
184
+ body: responseBody
185
+ });
186
+
187
+ // Visit the application under test
188
+ cy.visit('/')
189
+ })
190
+
191
+ cy.contains("Hello World")
192
+ })
193
+ })
194
+ ```
166
195
 
167
196
  ### Example of loading rails test fixtures
168
197
  ```ruby
@@ -0,0 +1,109 @@
1
+ # Setting up associations with the correct data
2
+
3
+ You cannot access associations directly from Cypress like you can do with ruby tests.
4
+ So setting up associations has to be done differently from within Cypress.
5
+
6
+ There are a few ways you can setup associations with the correct data using Cypress and FactoryBot.
7
+ 1. Setting the foreign keys
8
+ 2. Using transient attributes
9
+ 3. Using Nested Attributes
10
+ 4. Combination of the above depending on your situation
11
+
12
+ Assuming you have the following models
13
+
14
+ ```rb
15
+ class Post < ApplicationRecord
16
+ belongs_to :author
17
+ accepts_nested_attributes_for :author
18
+ end
19
+
20
+ class Author < ApplicationRecord
21
+ has_many :posts
22
+ accepts_nested_attributes_for :posts
23
+ end
24
+ ```
25
+
26
+ You can do the following:
27
+
28
+ ## 1. Setting the foreign keys
29
+
30
+ factories.rb
31
+ ```rb
32
+ FactoryBot.define do
33
+ factory :author do
34
+ name { 'Taylor' }
35
+ end
36
+
37
+ factory :post do
38
+ title { 'Cypress on Rails is Awesome' }
39
+ author_id { create(:author).id }
40
+ end
41
+ end
42
+ ```
43
+
44
+ then in Cypress
45
+ ```js
46
+ // example with overriding the defaults
47
+ cy.appFactories([['create', 'author', { name: 'James' }]]).then((records) => {
48
+ cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_id: records[0].id }]]
49
+ });
50
+
51
+ // example without overriding anything
52
+ cy.appFactories([['create', 'author']]).then((records) => {
53
+ cy.appFactories([['create', 'post', { author_id: records[0].id }]]
54
+ });
55
+ ```
56
+
57
+ ## 2. Using transient attributes
58
+
59
+ ```rb
60
+ FactoryBot.define do
61
+ factory :author do
62
+ name { 'Taylor' }
63
+ end
64
+
65
+ factory :post do
66
+ transient do
67
+ author_name { 'Taylor' }
68
+ end
69
+ title { 'Cypress on Rails is Awesome' }
70
+ author { create(:author, name: author_name ) }
71
+ end
72
+ end
73
+ ```
74
+
75
+ then in Cypress
76
+ ```js
77
+ // example with overriding the defaults
78
+ cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_name: 'James' }]]
79
+
80
+ // example without overriding
81
+ cy.appFactories([['create', 'post']]
82
+ ```
83
+
84
+ ## 3. Using Nested Attributes
85
+
86
+ ```rb
87
+ FactoryBot.define do
88
+ factory :author do
89
+ name { 'Taylor' }
90
+ end
91
+
92
+ factory :post do
93
+ title { 'Cypress on Rails is Awesome' }
94
+ author_attributes { { name: 'Taylor' } }
95
+ end
96
+ end
97
+ ```
98
+
99
+ then in Cypress
100
+ ```js
101
+ // example with overriding the defaults
102
+ cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_attributes: { name: 'James' } }]]
103
+
104
+ // example without overriding
105
+ cy.appFactories([['create', 'post']]
106
+
107
+ // example of creating author with multiple posts
108
+ cy.appFactories([['create', 'author', { name: 'James', posts_attributes: [{ name: 'Cypress is cool' }, {name: 'Rails is awesome' }] ]]
109
+ ```
@@ -53,18 +53,23 @@ module CypressOnRails
53
53
  body = JSON.parse(req.body.read)
54
54
  logger.info "handle_command: #{body}"
55
55
  commands = Command.from_body(body, configuration)
56
- missing_command = commands.find {|command| !@file.exists?(command.file_path) }
56
+ missing_command = commands.find {|command| !@file.exist?(command.file_path) }
57
57
 
58
58
  if missing_command.nil?
59
- results = commands.map { |command| @command_executor.perform(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,18 @@ 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
+
30
+ def self.reload
31
+ instance.reload
32
+ end
33
+
22
34
  # @return [Array]
23
35
  attr_accessor :factory
24
36
  attr_accessor :always_reload
@@ -36,7 +48,7 @@ module CypressOnRails
36
48
  end
37
49
 
38
50
  def create(*options)
39
- load_files
51
+ auto_reload
40
52
  factory_name = options.shift
41
53
  if options.last.is_a?(Hash)
42
54
  args = options.pop
@@ -47,10 +59,36 @@ module CypressOnRails
47
59
  end
48
60
 
49
61
  def create_list(*args)
50
- load_files
62
+ auto_reload
51
63
  factory.create_list(*args)
52
64
  end
53
65
 
66
+ def build(*options)
67
+ auto_reload
68
+ factory_name = options.shift
69
+ if options.last.is_a?(Hash)
70
+ args = options.pop
71
+ else
72
+ args = {}
73
+ end
74
+ factory.build(factory_name, *options.map(&:to_sym), args.symbolize_keys)
75
+ end
76
+
77
+ def build_list(*args)
78
+ auto_reload
79
+ factory.build_list(*args)
80
+ end
81
+
82
+ def reload
83
+ @latest_mtime = current_latest_mtime
84
+ logger.info 'Loading Factories'
85
+ factory.reload
86
+ files.each do |file|
87
+ logger.debug "-- Loading: #{file}"
88
+ @kernel.load(file)
89
+ end
90
+ end
91
+
54
92
  private
55
93
 
56
94
  # @param [String,Array] arg
@@ -68,20 +106,17 @@ module CypressOnRails
68
106
  CypressOnRails.configuration.logger
69
107
  end
70
108
 
71
- def load_files
72
- current_latest_mtime = files.map{|file| @file_system.mtime(file) }.max
73
- return unless should_reload?(current_latest_mtime)
74
- logger.info 'Loading Factories'
75
- @latest_mtime = current_latest_mtime
76
- factory.reload
77
- files.each do |file|
78
- logger.debug "-- Loading: #{file}"
79
- @kernel.load(file)
80
- end
109
+ def current_latest_mtime
110
+ files.map{|file| @file_system.mtime(file) }.max
111
+ end
112
+
113
+ def auto_reload
114
+ return unless should_reload?
115
+ reload
81
116
  end
82
117
 
83
- def should_reload?(current_latest_mtime)
118
+ def should_reload?
84
119
  @always_reload || @latest_mtime.nil? || @latest_mtime < current_latest_mtime
85
120
  end
86
121
  end
87
- end
122
+ end
@@ -1,3 +1,3 @@
1
1
  module CypressOnRails
2
- VERSION = '1.9.1'.freeze
2
+ VERSION = '1.12.1'.freeze
3
3
  end
@@ -7,4 +7,6 @@ else
7
7
  Post.delete_all if defined?(Post)
8
8
  end
9
9
 
10
+ CypressOnRails::SmartFactoryWrapper.reload
11
+
10
12
  Rails.logger.info "APPCLEANED" # used by log_fail.rb
@@ -3,6 +3,8 @@ filename = command_options.fetch('runnable_full_title', 'no title').gsub(/[^[:pr
3
3
 
4
4
  # grab last lines until "APPCLEANED" (Make sure in clean.rb to log the text "APPCLEANED")
5
5
  system "tail -n 10000 -r log/#{Rails.env}.log | sed \"/APPCLEANED/ q\" | sed 'x;1!H;$!d;x' > 'log/#{filename}.log'"
6
+ # Alternative command if the above does not work
7
+ # system "tail -n 10000 log/#{Rails.env}.log | tac | sed \"/APPCLEANED/ q\" | sed 'x;1!H;$!d;x' > 'log/#{filename}.log'"
6
8
 
7
9
  # create a json debug file for server debugging
8
10
  json_result = {}
@@ -29,7 +29,7 @@ factory = FactoryBot if defined?(FactoryBot)
29
29
  factory = FactoryGirl if defined?(FactoryGirl)
30
30
 
31
31
  CypressOnRails::SmartFactoryWrapper.configure(
32
- always_reload: !Rails.configuration.cache_classes,
32
+ always_reload: false,
33
33
  factory: factory,
34
34
  files: [
35
35
  Rails.root.join('spec', 'factories.rb'),
@@ -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
  });
@@ -17,14 +17,14 @@ RSpec.describe CypressOnRails::Middleware do
17
17
  context '/__cypress__/command' do
18
18
  before do
19
19
  allow(command_executor).to receive(:perform).and_return({ id: 1, title: 'some result' })
20
- allow(file).to receive(:exists?)
20
+ allow(file).to receive(:exist?)
21
21
  env['PATH_INFO'] = '/__cypress__/command'
22
22
  end
23
23
 
24
- it 'command file exists' do
24
+ it 'command file exist' do
25
25
  allow(command_executor).to receive(:perform).and_return({ id: 1, title: 'some result' })
26
26
  env['rack.input'] = rack_input(name: 'seed')
27
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
27
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/seed.rb').and_return(true)
28
28
 
29
29
  aggregate_failures do
30
30
  expect(response).to eq([201,
@@ -34,9 +34,9 @@ RSpec.describe CypressOnRails::Middleware do
34
34
  end
35
35
  end
36
36
 
37
- it 'command file exists with options' do
37
+ it 'command file exist with options' do
38
38
  env['rack.input'] = rack_input(name: 'seed', options: ['my_options'])
39
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
39
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/seed.rb').and_return(true)
40
40
 
41
41
  aggregate_failures do
42
42
  expect(response).to eq([201,
@@ -46,11 +46,11 @@ RSpec.describe CypressOnRails::Middleware do
46
46
  end
47
47
  end
48
48
 
49
- it 'command file does not exists' do
49
+ it 'command file does not exist' do
50
50
  object = BasicObject.new
51
51
  allow(command_executor).to receive(:perform).and_return(object)
52
52
  env['rack.input'] = rack_input(name: 'seed')
53
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
53
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/seed.rb').and_return(true)
54
54
 
55
55
  aggregate_failures do
56
56
  expect(response).to eq([201,
@@ -62,7 +62,7 @@ RSpec.describe CypressOnRails::Middleware do
62
62
 
63
63
  it 'command result does not respond to to_json' do
64
64
  env['rack.input'] = rack_input(name: 'seed')
65
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
65
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/seed.rb').and_return(true)
66
66
 
67
67
  aggregate_failures do
68
68
  expect(response).to eq([201,
@@ -75,8 +75,8 @@ RSpec.describe CypressOnRails::Middleware do
75
75
  it 'running multiple commands' do
76
76
  env['rack.input'] = rack_input([{name: 'load_user'},
77
77
  {name: 'load_sample', options: {'all' => 'true'}}])
78
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_user.rb').and_return(true)
79
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_sample.rb').and_return(true)
78
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/load_user.rb').and_return(true)
79
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/load_sample.rb').and_return(true)
80
80
 
81
81
  aggregate_failures do
82
82
  expect(response).to eq([201,
@@ -89,8 +89,8 @@ RSpec.describe CypressOnRails::Middleware do
89
89
 
90
90
  it 'running multiple commands but one missing' do
91
91
  env['rack.input'] = rack_input([{name: 'load_user'}, {name: 'load_sample'}])
92
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_user.rb').and_return(true)
93
- allow(file).to receive(:exists?).with('spec/cypress/app_commands/load_sample.rb').and_return(false)
92
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/load_user.rb').and_return(true)
93
+ allow(file).to receive(:exist?).with('spec/cypress/app_commands/load_sample.rb').and_return(false)
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']])
@@ -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)
@@ -115,6 +140,13 @@ RSpec.describe CypressOnRails::SmartFactoryWrapper do
115
140
  expect(kernel_double).to have_received(:load).with('file2.rb').twice
116
141
  end
117
142
 
143
+ it 'can manually reload' do
144
+ subject.reload
145
+ expect(factory_double).to have_received(:reload)
146
+ expect(kernel_double).to have_received(:load).with('file1.rb')
147
+ expect(kernel_double).to have_received(:load).with('file2.rb')
148
+ end
149
+
118
150
  context 'files is a string' do
119
151
  let(:files) { 'file*.rb' }
120
152
 
@@ -4,9 +4,9 @@ set -eo pipefail
4
4
  echo '--- testing rails 3.2'
5
5
 
6
6
  echo '-- setting environment'
7
- DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8
- RAILS_ENV=test
9
- BUNDLE_GEMFILE="$DIR/Gemfile"
7
+ export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8
+ export RAILS_ENV=test
9
+ export BUNDLE_GEMFILE="$DIR/Gemfile"
10
10
  cd $DIR
11
11
 
12
12
  echo '-- bundle install'
@@ -4,9 +4,9 @@ set -eo pipefail
4
4
  echo '--- testing rails 4.2'
5
5
 
6
6
  echo '-- setting environment'
7
- DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8
- RAILS_ENV=test
9
- BUNDLE_GEMFILE="$DIR/Gemfile"
7
+ export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8
+ export RAILS_ENV=test
9
+ export BUNDLE_GEMFILE="$DIR/Gemfile"
10
10
  cd $DIR
11
11
 
12
12
  echo '-- bundle install'
@@ -4,14 +4,15 @@ set -eo pipefail
4
4
  echo '--- testing rails 5.2'
5
5
 
6
6
  echo '-- setting environment'
7
- DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8
- RAILS_ENV=test
9
- BUNDLE_GEMFILE="$DIR/Gemfile"
7
+ export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8
+ export RAILS_ENV=test
9
+ export BUNDLE_GEMFILE="$DIR/Gemfile"
10
10
  cd $DIR
11
11
 
12
12
  echo '-- bundle install'
13
13
  bundle --version
14
- bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2 --path vendor/bundle
14
+ bundle config set --local path 'vendor/bundle'
15
+ bundle install --quiet --gemfile="$DIR/Gemfile" --retry 2
15
16
 
16
17
  echo '-- migration'
17
18
  bundle exec ./bin/rails db:drop || true
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.9.1
4
+ version: 1.12.1
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-03-11 00:00:00.000000000 Z
12
+ date: 2022-01-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -90,9 +90,9 @@ extensions: []
90
90
  extra_rdoc_files: []
91
91
  files:
92
92
  - ".github/FUNDING.yml"
93
+ - ".github/workflows/ruby.yml"
93
94
  - ".gitignore"
94
95
  - ".rspec"
95
- - ".travis.yml"
96
96
  - CHANGELOG.md
97
97
  - Gemfile
98
98
  - LICENSE
@@ -100,6 +100,7 @@ files:
100
100
  - Rakefile
101
101
  - cypress-on-rails.gemspec
102
102
  - docs/authentication.md
103
+ - docs/factory_bot_associations.md
103
104
  - lib/cypress-on-rails.rb
104
105
  - lib/cypress/smart_factory_wrapper.rb
105
106
  - lib/cypress_dev.rb
@@ -323,7 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
323
324
  - !ruby/object:Gem::Version
324
325
  version: '0'
325
326
  requirements: []
326
- rubygems_version: 3.2.11
327
+ rubygems_version: 3.2.25
327
328
  signing_key:
328
329
  specification_version: 4
329
330
  summary: Integrates cypress with rails or rack applications
data/.travis.yml DELETED
@@ -1,39 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.3
4
- - 2.4
5
- - 2.5
6
- - 2.6
7
- # - 2.7
8
-
9
- #addons:
10
- # artifacts:
11
- # s3_region: "ap-southeast-2"
12
- # paths:
13
- # - $(ls spec/integrations/*/*/cypress/{screenshots,videos}/* | tr "\n" ":")
14
- # - $(ls spec/integrations/rails_3_2/cypress/{screenshots,videos}/* | tr "\n" ":")
15
-
16
- cache:
17
- directories:
18
- - spec/integrations/rails_5_2/spec/node_modules
19
- - spec/integrations/rails_5_2/vendor/bundle
20
- - spec/integrations/rails_4_2/test/node_modules
21
- - spec/integrations/rails_4_2/vendor/bundle
22
- - spec/integrations/rails_3_2/node_modules
23
- - spec/integrations/rails_3_2/vendor/bundle
24
-
25
- before_install:
26
- - sudo apt-get -qq update
27
- - sudo apt-get install -y build-essential patch ruby-dev zlib1g-dev liblzma-dev libxml2-dev
28
- - sudo apt-get install -y xvfb libgtk2.0-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2
29
- - travis_retry nvm install 14.13.1
30
- - node -v
31
- - nvm alias default 14.13.1
32
-
33
- script:
34
- - bundle exec rake
35
- - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
36
- - gem install bundler -v '< 2'
37
- - ./spec/integrations/rails_5_2/test.sh
38
- - ./spec/integrations/rails_4_2/test.sh
39
- - ./spec/integrations/rails_3_2/test.sh