cypress-on-rails 1.10.1 → 1.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +63 -0
- data/.gitignore +5 -1
- data/CHANGELOG.md +65 -2
- data/README.md +261 -62
- data/cypress-on-rails.gemspec +1 -0
- data/docs/authentication.md +12 -10
- data/docs/factory_bot_associations.md +109 -0
- data/lib/cypress-on-rails.rb +2 -2
- data/lib/cypress_on_rails/command_executor.rb +9 -5
- data/lib/cypress_on_rails/configuration.rb +17 -2
- data/lib/cypress_on_rails/middleware.rb +15 -16
- data/lib/cypress_on_rails/middleware_config.rb +17 -0
- data/lib/cypress_on_rails/railtie.rb +5 -1
- data/lib/cypress_on_rails/smart_factory_wrapper.rb +49 -14
- data/lib/cypress_on_rails/vcr_middleware.rb +73 -0
- data/lib/cypress_on_rails/version.rb +1 -1
- data/lib/generators/cypress_on_rails/install_generator.rb +48 -30
- data/lib/generators/cypress_on_rails/templates/config/initializers/cypress_on_rails.rb.erb +3 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/advance_factory_bot_spec.js → e2e/rails_examples/advance_factory_bot.cy.js} +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/other_spec.js → e2e/rails_examples/other.cy.js} +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/using_factory_bot_spec.js → e2e/rails_examples/using_factory_bot.cy.js} +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/using_fixtures_spec.js → e2e/rails_examples/using_fixtures.cy.js} +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/{integration/rails_examples/using_scenarios_spec.js → e2e/rails_examples/using_scenarios.cy.js} +1 -1
- data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_vcr.cy.js +24 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/support/{index.js → index.js.erb} +1 -0
- data/lib/generators/cypress_on_rails/templates/spec/cypress/support/on-rails.js +9 -7
- data/lib/generators/cypress_on_rails/templates/spec/cypress.config.js +9 -0
- data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/clean.rb +8 -0
- data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/log_fail.rb +2 -0
- data/lib/generators/cypress_on_rails/templates/spec/{cypress/cypress_helper.rb → e2e/e2e_helper.rb.erb} +6 -1
- data/lib/generators/cypress_on_rails/templates/spec/playwright/e2e/rails_examples/using_scenarios.spec.js +12 -0
- data/lib/generators/cypress_on_rails/templates/spec/playwright/support/index.js.erb +21 -0
- data/lib/generators/cypress_on_rails/templates/spec/playwright/support/on-rails.js +37 -0
- data/lib/generators/cypress_on_rails/templates/spec/playwright.config.js +79 -0
- data/lib/generators/cypress_on_rails/update_generator.rb +14 -3
- data/plugin/.gitignore +1 -0
- data/plugin/cypress/plugins/index.js +4 -0
- data/plugin/package.json +31 -0
- data/plugin/support/index.js +37 -0
- data/spec/cypress_on_rails/command_executor_spec.rb +1 -1
- data/spec/cypress_on_rails/configuration_spec.rb +6 -3
- data/spec/cypress_on_rails/middleware_spec.rb +24 -22
- data/spec/cypress_on_rails/smart_factory_wrapper_spec.rb +33 -1
- data/spec/cypress_on_rails/vcr_middleware_spec.rb +119 -0
- data/specs_e2e/cypress.config.js +10 -0
- data/specs_e2e/playwright.config.js +79 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/.gitignore +1 -1
- data/specs_e2e/rails_3_2/.ruby_version +1 -0
- data/{spec/integrations → specs_e2e}/rails_3_2/Gemfile +1 -1
- data/{spec/integrations → specs_e2e}/rails_3_2/test.sh +17 -11
- data/{spec/integrations → specs_e2e}/rails_4_2/.gitignore +3 -2
- data/{spec/integrations → specs_e2e}/rails_4_2/Gemfile +3 -1
- data/specs_e2e/rails_4_2/app/controllers/using_vcr_controller.rb +10 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/app/models/post.rb +3 -1
- data/specs_e2e/rails_4_2/app/views/using_vcr/index.html.erb +6 -0
- data/specs_e2e/rails_4_2/app/views/using_vcr/record_cats.html.erb +7 -0
- data/{spec/integrations → specs_e2e}/rails_4_2/config/routes.rb +5 -0
- data/specs_e2e/rails_4_2/package.json +10 -0
- data/specs_e2e/rails_4_2/test.sh +44 -0
- data/{spec/integrations → specs_e2e}/rails_5_2/.gitignore +1 -1
- data/{spec/integrations → specs_e2e}/rails_5_2/Gemfile +1 -1
- data/specs_e2e/rails_5_2/app/assets/javascripts/posts.js +2 -0
- data/specs_e2e/rails_5_2/app/assets/stylesheets/posts.css +4 -0
- data/specs_e2e/rails_5_2/test.sh +48 -0
- metadata +190 -177
- data/.travis.yml +0 -39
- data/lib/generators/cypress_on_rails/templates/spec/cypress/fixtures/example.json +0 -5
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/actions.spec.js +0 -272
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/aliasing.spec.js +0 -42
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/assertions.spec.js +0 -63
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/connectors.spec.js +0 -55
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cookies.spec.js +0 -78
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/cypress_api.spec.js +0 -211
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/files.spec.js +0 -86
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/local_storage.spec.js +0 -52
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/location.spec.js +0 -32
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/misc.spec.js +0 -68
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/navigation.spec.js +0 -54
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/network_requests.spec.js +0 -108
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/querying.spec.js +0 -65
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/spies_stubs_clocks.spec.js +0 -62
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/traversal.spec.js +0 -121
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/utilities.spec.js +0 -89
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/viewport.spec.js +0 -59
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/waiting.spec.js +0 -34
- data/lib/generators/cypress_on_rails/templates/spec/cypress/integration/examples/window.spec.js +0 -22
- data/lib/generators/cypress_on_rails/templates/spec/cypress.json +0 -4
- data/spec/integrations/cypress.json +0 -5
- data/spec/integrations/rails_4_2/test.sh +0 -38
- data/spec/integrations/rails_5_2/test.sh +0 -41
- data/spec/integrations/rails_5_2/tmp/.keep +0 -0
- data/spec/integrations/rails_5_2/vendor/.keep +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/activerecord_fixtures.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/eval.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/factory_bot.rb +0 -0
- /data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/scenarios/basic.rb +0 -0
- /data/spec/cypress_on_rails/command_executor/{cypress_helper.rb → e2e_helper.rb} +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/README.rdoc +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/Rakefile +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/app/assets/stylesheets/application.css +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/app/controllers/application_controller.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/app/controllers/welcome_controller.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/app/helpers/application_helper.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/app/models/post.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/app/views/layouts/application.html.erb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/app/views/welcome/index.html.erb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/bin/rails +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config/application.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config/boot.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config/environment.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config/environments/development.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config/environments/production.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config/environments/test.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/backtrace_silencers.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/inflections.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/mime_types.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/secret_token.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/session_store.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config/initializers/wrap_parameters.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config/locales/en.yml +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config/routes.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/config.ru +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/log/.keep +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/public/404.html +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/public/422.html +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/public/500.html +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/public/favicon.ico +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/public/robots.txt +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/tmp/.keep +0 -0
- /data/{spec/integrations → specs_e2e}/rails_3_2/vendor/.gitkeep +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/README.rdoc +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/Rakefile +0 -0
- /data/{spec/integrations/rails_5_2/app/assets/javascripts/posts.js → specs_e2e/rails_4_2/app/assets/javascripts/using_vcr.js} +0 -0
- /data/{spec/integrations/rails_5_2/app/assets/stylesheets/posts.css → specs_e2e/rails_4_2/app/assets/stylesheets/using_vcr.css} +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/app/controllers/application_controller.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/app/controllers/welcome_controller.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/app/views/layouts/application.html.erb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/app/views/welcome/index.html.erb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/bin/bundle +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/bin/rails +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/bin/rake +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/bin/setup +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/application.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/boot.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/environment.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/environments/development.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/environments/production.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/environments/test.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/backtrace_silencers.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/cookies_serializer.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/filter_parameter_logging.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/inflections.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/mime_types.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/session_store.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/to_time_preserves_timezone.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/initializers/wrap_parameters.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/locales/en.yml +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config/secrets.yml +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/config.ru +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/public/404.html +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/public/422.html +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/public/500.html +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/public/favicon.ico +0 -0
- /data/{spec/integrations → specs_e2e}/rails_4_2/public/robots.txt +0 -0
- /data/{spec/integrations/rails_4_2/log → specs_e2e/rails_4_2/spec}/.keep +0 -0
- /data/{spec/integrations/rails_4_2/spec → specs_e2e/rails_4_2/vendor}/.keep +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/README.md +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/Rakefile +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/app/assets/stylesheets/scaffold.css +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/app/controllers/application_controller.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/app/controllers/posts_controller.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/app/helpers/posts_helper.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/app/jobs/application_job.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/app/models/application_record.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/app/models/post.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/app/views/layouts/application.html.erb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/_form.html.erb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/edit.html.erb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/index.html.erb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/new.html.erb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/app/views/posts/show.html.erb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/app/views/welcome/index.html.erb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/bin/bundle +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/bin/rails +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/bin/rake +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/bin/setup +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/bin/update +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/application.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/boot.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/credentials.yml.enc +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/database.yml +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/environment.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/environments/development.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/environments/production.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/environments/test.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/application_controller_renderer.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/backtrace_silencers.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/content_security_policy.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/cookies_serializer.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/filter_parameter_logging.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/inflections.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/mime_types.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/initializers/wrap_parameters.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/locales/en.yml +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/master.key +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config/routes.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/config.ru +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/db/migrate/20180621085832_create_posts.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/public/404.html +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/public/422.html +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/public/500.html +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/public/apple-touch-icon-precomposed.png +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/public/apple-touch-icon.png +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/public/favicon.ico +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/public/robots.txt +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/test/controllers/posts_controller_test.rb +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/test/cypress_fixtures/posts.yml +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/test/fixtures/posts.yml +0 -0
- /data/{spec/integrations → specs_e2e}/rails_5_2/test/models/post_test.rb +0 -0
- /data/{spec/integrations/rails_4_2 → specs_e2e/rails_5_2}/vendor/.keep +0 -0
- /data/{spec/integrations/rails_5_2/log/.keep → tmp/pids/.gitkeep} +0 -0
data/lib/generators/cypress_on_rails/templates/spec/cypress/e2e/rails_examples/using_vcr.cy.js
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
describe('Rails Other examples', function() {
|
2
|
+
it('Inserting a cassette', function() {
|
3
|
+
cy.app('clean') // have a look at e2e/app_commands/clean.rb
|
4
|
+
|
5
|
+
cy.vcr_insert_cassette('cats', { record: "new_episodes" })
|
6
|
+
cy.visit('/using_vcr/index')
|
7
|
+
|
8
|
+
cy.get('a').contains('Cats').click()
|
9
|
+
cy.contains('Record from Cats API');
|
10
|
+
|
11
|
+
cy.vcr_eject_cassette();
|
12
|
+
})
|
13
|
+
|
14
|
+
it('Using previous a cassette', function() {
|
15
|
+
cy.app('clean') // have a look at cypress/app_commands/clean.rb
|
16
|
+
|
17
|
+
cy.vcr_insert_cassette('cats')
|
18
|
+
cy.visit('/using_vcr/index')
|
19
|
+
cy.get('a').contains('Cats').click()
|
20
|
+
cy.contains('Record from Cats API');
|
21
|
+
|
22
|
+
cy.vcr_eject_cassette();
|
23
|
+
})
|
24
|
+
})
|
@@ -1,16 +1,18 @@
|
|
1
1
|
// CypressOnRails: dont remove these command
|
2
2
|
Cypress.Commands.add('appCommands', function (body) {
|
3
|
-
|
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
|
-
url: "/
|
7
|
+
url: "/__e2e__/command",
|
7
8
|
body: JSON.stringify(body),
|
8
|
-
log:
|
9
|
+
log: false,
|
9
10
|
failOnStatusCode: false
|
10
11
|
}).then((response) => {
|
11
|
-
|
12
|
-
|
13
|
-
expect(response.body.
|
12
|
+
log.end();
|
13
|
+
if (response.status !== 201) {
|
14
|
+
expect(response.body.message).to.equal('')
|
15
|
+
expect(response.status).to.be.equal(201)
|
14
16
|
}
|
15
17
|
return response.body
|
16
18
|
});
|
@@ -48,7 +50,7 @@ Cypress.Commands.add('appFixtures', function (options) {
|
|
48
50
|
Cypress.on('fail', (err, runnable) => {
|
49
51
|
// allow app to generate additional logging data
|
50
52
|
Cypress.$.ajax({
|
51
|
-
url: '/
|
53
|
+
url: '/__e2e__/command',
|
52
54
|
data: JSON.stringify({name: 'log_fail', options: {error_message: err.message, runnable_full_title: runnable.fullTitle() }}),
|
53
55
|
async: false,
|
54
56
|
method: 'POST'
|
@@ -7,4 +7,12 @@ else
|
|
7
7
|
Post.delete_all if defined?(Post)
|
8
8
|
end
|
9
9
|
|
10
|
+
CypressOnRails::SmartFactoryWrapper.reload
|
11
|
+
|
12
|
+
if defined?(VCR)
|
13
|
+
VCR.eject_cassette # make sure we no cassette inserted before the next test starts
|
14
|
+
VCR.turn_off!
|
15
|
+
WebMock.disable! if defined?(WebMock)
|
16
|
+
end
|
17
|
+
|
10
18
|
Rails.logger.info "APPCLEANED" # used by log_fail.rb
|
data/lib/generators/cypress_on_rails/templates/spec/{cypress → e2e}/app_commands/log_fail.rb
RENAMED
@@ -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,10 +29,15 @@ factory = FactoryBot if defined?(FactoryBot)
|
|
29
29
|
factory = FactoryGirl if defined?(FactoryGirl)
|
30
30
|
|
31
31
|
CypressOnRails::SmartFactoryWrapper.configure(
|
32
|
-
always_reload:
|
32
|
+
always_reload: false,
|
33
33
|
factory: factory,
|
34
34
|
files: [
|
35
35
|
Rails.root.join('spec', 'factories.rb'),
|
36
36
|
Rails.root.join('spec', 'factories', '**', '*.rb')
|
37
37
|
]
|
38
38
|
)
|
39
|
+
|
40
|
+
<% unless options.experimental %># <% end %>require 'vcr'
|
41
|
+
<% unless options.experimental %># <% end %>VCR.configure do |config|
|
42
|
+
<% unless options.experimental %># <% end %> config.hook_into :webmock
|
43
|
+
<% unless options.experimental %># <% end %>end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { test, expect } from "@playwright/test";
|
2
|
+
import { app, appScenario } from '../../support/on-rails';
|
3
|
+
|
4
|
+
test.describe("Rails using scenarios examples", () => {
|
5
|
+
test.beforeEach(async ({ page }) => {
|
6
|
+
await app('clean');
|
7
|
+
});
|
8
|
+
|
9
|
+
test("setup basic scenario", async ({ page }) => {
|
10
|
+
await appScenario('basic');
|
11
|
+
await page.goto("/"); });
|
12
|
+
});
|
@@ -0,0 +1,21 @@
|
|
1
|
+
// ***********************************************************
|
2
|
+
// This example support/index.js is processed and
|
3
|
+
// loaded automatically before your test files.
|
4
|
+
//
|
5
|
+
// This is a great place to put global configuration and
|
6
|
+
// behavior that modifies Cypress.
|
7
|
+
//
|
8
|
+
// You can change the location of this file or turn off
|
9
|
+
// automatically serving support files with the
|
10
|
+
// 'supportFile' configuration option.
|
11
|
+
//
|
12
|
+
// You can read more here:
|
13
|
+
// https://on.cypress.io/configuration
|
14
|
+
// ***********************************************************
|
15
|
+
|
16
|
+
// Import commands.js using ES2015 syntax:
|
17
|
+
import './on-rails'
|
18
|
+
<% unless options.experimental %>// <% end %>import 'cypress-on-rails/support/index'
|
19
|
+
|
20
|
+
// Alternatively you can use CommonJS syntax:
|
21
|
+
// require('./commands')
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { request, expect } from '@playwright/test'
|
2
|
+
import config from '../../playwright.config'
|
3
|
+
|
4
|
+
const contextPromise = request.newContext({ baseURL: config.use ? config.use.baseURL : 'http://localhost:5017' })
|
5
|
+
|
6
|
+
const appCommands = async (data) => {
|
7
|
+
const context = await contextPromise
|
8
|
+
const response = await context.post('/__e2e__/command', { data })
|
9
|
+
|
10
|
+
expect(response.ok()).toBeTruthy()
|
11
|
+
return response.body
|
12
|
+
}
|
13
|
+
|
14
|
+
const app = (name, options = {}) => appCommands({ name, options }).then((body) => body[0])
|
15
|
+
const appScenario = (name, options = {}) => app('scenarios/' + name, options)
|
16
|
+
const appEval = (code) => app('eval', code)
|
17
|
+
const appFactories = (options) => app('factory_bot', options)
|
18
|
+
|
19
|
+
const appVcrInsertCassette = async (cassette_name, options) => {
|
20
|
+
const context = await contextPromise;
|
21
|
+
if (!options) options = {};
|
22
|
+
|
23
|
+
Object.keys(options).forEach(key => options[key] === undefined ? delete options[key] : {});
|
24
|
+
const response = await context.post("/__e2e__/vcr/insert", {data: [cassette_name,options]});
|
25
|
+
expect(response.ok()).toBeTruthy();
|
26
|
+
return response.body;
|
27
|
+
}
|
28
|
+
|
29
|
+
const appVcrEjectCassette = async () => {
|
30
|
+
const context = await contextPromise;
|
31
|
+
|
32
|
+
const response = await context.post("/__e2e__/vcr/eject");
|
33
|
+
expect(response.ok()).toBeTruthy();
|
34
|
+
return response.body;
|
35
|
+
}
|
36
|
+
|
37
|
+
export { appCommands, app, appScenario, appEval, appFactories, appVcrInsertCassette, appVcrEjectCassette }
|
@@ -0,0 +1,79 @@
|
|
1
|
+
// @ts-check
|
2
|
+
const { defineConfig, devices } = require('@playwright/test');
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Read environment variables from file.
|
6
|
+
* https://github.com/motdotla/dotenv
|
7
|
+
*/
|
8
|
+
// require('dotenv').config();
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @see https://playwright.dev/docs/test-configuration
|
12
|
+
*/
|
13
|
+
module.exports = defineConfig({
|
14
|
+
testDir: './playwright/e2e',
|
15
|
+
/* Run tests in files in parallel */
|
16
|
+
fullyParallel: true,
|
17
|
+
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
18
|
+
forbidOnly: !!process.env.CI,
|
19
|
+
/* Retry on CI only */
|
20
|
+
retries: process.env.CI ? 2 : 0,
|
21
|
+
/* Opt out of parallel tests on CI. */
|
22
|
+
workers: process.env.CI ? 1 : undefined,
|
23
|
+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
24
|
+
reporter: 'html',
|
25
|
+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
26
|
+
use: {
|
27
|
+
/* Base URL to use in actions like `await page.goto('/')`. */
|
28
|
+
baseURL: 'http://127.0.0.1:5017',
|
29
|
+
|
30
|
+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
31
|
+
trace: 'on-first-retry',
|
32
|
+
},
|
33
|
+
|
34
|
+
/* Configure projects for major browsers */
|
35
|
+
projects: [
|
36
|
+
{
|
37
|
+
name: 'chromium',
|
38
|
+
use: { ...devices['Desktop Chrome'] },
|
39
|
+
},
|
40
|
+
|
41
|
+
{
|
42
|
+
name: 'firefox',
|
43
|
+
use: { ...devices['Desktop Firefox'] },
|
44
|
+
},
|
45
|
+
|
46
|
+
{
|
47
|
+
name: 'webkit',
|
48
|
+
use: { ...devices['Desktop Safari'] },
|
49
|
+
},
|
50
|
+
|
51
|
+
/* Test against mobile viewports. */
|
52
|
+
// {
|
53
|
+
// name: 'Mobile Chrome',
|
54
|
+
// use: { ...devices['Pixel 5'] },
|
55
|
+
// },
|
56
|
+
// {
|
57
|
+
// name: 'Mobile Safari',
|
58
|
+
// use: { ...devices['iPhone 12'] },
|
59
|
+
// },
|
60
|
+
|
61
|
+
/* Test against branded browsers. */
|
62
|
+
// {
|
63
|
+
// name: 'Microsoft Edge',
|
64
|
+
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
65
|
+
// },
|
66
|
+
// {
|
67
|
+
// name: 'Google Chrome',
|
68
|
+
// use: { ..devices['Desktop Chrome'], channel: 'chrome' },
|
69
|
+
// },
|
70
|
+
],
|
71
|
+
|
72
|
+
/* Run your local dev server before starting the tests */
|
73
|
+
// webServer: {
|
74
|
+
// command: 'npm run start',
|
75
|
+
// url: 'http://127.0.0.1:3000',
|
76
|
+
// reuseExistingServer: !process.env.CI,
|
77
|
+
// },
|
78
|
+
});
|
79
|
+
|
@@ -1,13 +1,24 @@
|
|
1
1
|
module CypressOnRails
|
2
2
|
class UpdateGenerator < Rails::Generators::Base
|
3
|
+
class_option :install_folder, type: :string, default: 'spec/e2e'
|
4
|
+
class_option :install_cypress, type: :boolean, default: true
|
5
|
+
class_option :install_playwright, type: :boolean, default: false
|
6
|
+
class_option :install_with, type: :string, default: 'yarn'
|
3
7
|
class_option :cypress_folder, type: :string, default: 'spec/cypress'
|
8
|
+
class_option :playwright_folder, type: :string, default: 'spec/playwright'
|
4
9
|
source_root File.expand_path('../templates', __FILE__)
|
5
10
|
|
6
11
|
def update_generated_files
|
7
12
|
template "config/initializers/cypress_on_rails.rb.erb", "config/initializers/cypress_on_rails.rb"
|
8
|
-
|
9
|
-
|
10
|
-
|
13
|
+
template "spec/e2e/e2e_helper.rb.erb", "#{options.install_folder}/e2e_helper.rb"
|
14
|
+
directory 'spec/e2e/app_commands', "#{options.install_folder}/app_commands"
|
15
|
+
|
16
|
+
if options.install_cypress
|
17
|
+
copy_file "spec/cypress/support/on-rails.js", "#{options.cypress_folder}/support/on-rails.js"
|
18
|
+
end
|
19
|
+
if options.install_playwright
|
20
|
+
copy_file "spec/playwright/support/on-rails.js", "#{options.playwright_folder}/support/on-rails.js"
|
21
|
+
end
|
11
22
|
end
|
12
23
|
end
|
13
24
|
end
|
data/plugin/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
node_modules
|
data/plugin/package.json
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
{
|
2
|
+
"name": "cypress-on-rails",
|
3
|
+
"version": "0.1.0",
|
4
|
+
"description": "Integrates cypress with rails or rack applications",
|
5
|
+
"main": "cypress/index.js",
|
6
|
+
"directories": {
|
7
|
+
"src": "cypress"
|
8
|
+
},
|
9
|
+
"scripts": {
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
11
|
+
"build": "tsc"
|
12
|
+
},
|
13
|
+
"repository": {
|
14
|
+
"type": "git",
|
15
|
+
"url": "git+https://github.com/shakacode/cypress-on-rails.git"
|
16
|
+
},
|
17
|
+
"keywords": [
|
18
|
+
"cypress",
|
19
|
+
"ruby",
|
20
|
+
"rails"
|
21
|
+
],
|
22
|
+
"author": "Grant Petersen-Speelman",
|
23
|
+
"license": "MIT",
|
24
|
+
"bugs": {
|
25
|
+
"url": "https://github.com/shakacode/cypress-on-rails/issues"
|
26
|
+
},
|
27
|
+
"homepage": "https://github.com/shakacode/cypress-on-rails#readme",
|
28
|
+
"dependencies": {
|
29
|
+
"cypress": "*"
|
30
|
+
}
|
31
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Cypress.Commands.add("vcr_insert_cassette", (cassette_name, options) => {
|
2
|
+
if (!options) options = {};
|
3
|
+
|
4
|
+
Object.keys(options).forEach(key => options[key] === undefined ? delete options[key] : {});
|
5
|
+
const log = Cypress.log({ name: "VCR Insert", message: cassette_name, autoEnd: false })
|
6
|
+
return cy.request({
|
7
|
+
method: 'POST',
|
8
|
+
url: "/__e2e__/vcr/insert",
|
9
|
+
body: JSON.stringify([cassette_name,options]),
|
10
|
+
log: false,
|
11
|
+
failOnStatusCode: false
|
12
|
+
}).then((response) => {
|
13
|
+
log.end();
|
14
|
+
if (response.status !== 201) {
|
15
|
+
expect(response.body.message).to.equal('')
|
16
|
+
expect(response.status).to.be.equal(201)
|
17
|
+
}
|
18
|
+
return response.body
|
19
|
+
});
|
20
|
+
});
|
21
|
+
|
22
|
+
Cypress.Commands.add("vcr_eject_cassette", () => {
|
23
|
+
const log = Cypress.log({ name: "VCR Eject", autoEnd: false })
|
24
|
+
return cy.request({
|
25
|
+
method: 'POST',
|
26
|
+
url: "/__e2e__/vcr/eject",
|
27
|
+
log: false,
|
28
|
+
failOnStatusCode: false
|
29
|
+
}).then((response) => {
|
30
|
+
log.end();
|
31
|
+
if (response.status !== 201) {
|
32
|
+
expect(response.body.message).to.equal('')
|
33
|
+
expect(response.status).to.be.equal(201)
|
34
|
+
}
|
35
|
+
return response.body
|
36
|
+
});
|
37
|
+
});
|
@@ -4,7 +4,8 @@ RSpec.describe CypressOnRails::Configuration do
|
|
4
4
|
it 'has defaults' do
|
5
5
|
CypressOnRails.configure { |config| config.reset }
|
6
6
|
|
7
|
-
expect(CypressOnRails.configuration.
|
7
|
+
expect(CypressOnRails.configuration.api_prefix).to eq('')
|
8
|
+
expect(CypressOnRails.configuration.install_folder).to eq('spec/e2e')
|
8
9
|
expect(CypressOnRails.configuration.use_middleware?).to eq(true)
|
9
10
|
expect(CypressOnRails.configuration.logger).to_not be_nil
|
10
11
|
end
|
@@ -12,11 +13,13 @@ RSpec.describe CypressOnRails::Configuration do
|
|
12
13
|
it 'can be configured' do
|
13
14
|
my_logger = Logger.new(STDOUT)
|
14
15
|
CypressOnRails.configure do |config|
|
15
|
-
config.
|
16
|
+
config.api_prefix = '/api'
|
17
|
+
config.install_folder = 'my/path'
|
16
18
|
config.use_middleware = false
|
17
19
|
config.logger = my_logger
|
18
20
|
end
|
19
|
-
expect(CypressOnRails.configuration.
|
21
|
+
expect(CypressOnRails.configuration.api_prefix).to eq('/api')
|
22
|
+
expect(CypressOnRails.configuration.install_folder).to eq('my/path')
|
20
23
|
expect(CypressOnRails.configuration.use_middleware?).to eq(false)
|
21
24
|
expect(CypressOnRails.configuration.logger).to eq(my_logger)
|
22
25
|
end
|
@@ -14,86 +14,88 @@ RSpec.describe CypressOnRails::Middleware do
|
|
14
14
|
StringIO.new(JSON.generate(json_value))
|
15
15
|
end
|
16
16
|
|
17
|
-
context '/
|
17
|
+
context '/__e2e__/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(:
|
21
|
-
env['PATH_INFO'] = '/
|
20
|
+
allow(file).to receive(:exist?)
|
21
|
+
env['PATH_INFO'] = '/__e2e__/command'
|
22
22
|
end
|
23
23
|
|
24
|
-
it 'command file
|
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(:
|
27
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/seed.rb').and_return(true)
|
28
28
|
|
29
29
|
aggregate_failures 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(:perform).with('spec/
|
33
|
+
expect(command_executor).to have_received(:perform).with('spec/e2e/app_commands/seed.rb', nil)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
it 'command file
|
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(:
|
39
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/seed.rb').and_return(true)
|
40
40
|
|
41
41
|
aggregate_failures 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(:perform).with('spec/
|
45
|
+
expect(command_executor).to have_received(:perform).with('spec/e2e/app_commands/seed.rb', ['my_options'])
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
it 'command file does not
|
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(:
|
53
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/seed.rb').and_return(true)
|
54
54
|
|
55
55
|
aggregate_failures 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(:perform).with('spec/
|
59
|
+
expect(command_executor).to have_received(:perform).with('spec/e2e/app_commands/seed.rb', nil)
|
60
60
|
end
|
61
61
|
end
|
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(:
|
65
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/seed.rb').and_return(true)
|
66
66
|
|
67
67
|
aggregate_failures 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(:perform).with('spec/
|
71
|
+
expect(command_executor).to have_received(:perform).with('spec/e2e/app_commands/seed.rb', nil)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
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(:
|
79
|
-
allow(file).to receive(:
|
78
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/load_user.rb').and_return(true)
|
79
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/load_sample.rb').and_return(true)
|
80
80
|
|
81
81
|
aggregate_failures 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(:perform).with('spec/
|
86
|
-
expect(command_executor).to have_received(:perform).with('spec/
|
85
|
+
expect(command_executor).to have_received(:perform).with('spec/e2e/app_commands/load_user.rb', nil)
|
86
|
+
expect(command_executor).to have_received(:perform).with('spec/e2e/app_commands/load_sample.rb', {'all' => 'true'})
|
87
87
|
end
|
88
88
|
end
|
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(:
|
93
|
-
allow(file).to receive(:
|
92
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/load_user.rb').and_return(true)
|
93
|
+
allow(file).to receive(:exist?).with('spec/e2e/app_commands/load_sample.rb').and_return(false)
|
94
94
|
|
95
95
|
aggregate_failures do
|
96
|
-
expect(response).to eq([404,
|
96
|
+
expect(response).to eq([404,
|
97
|
+
{"Content-Type"=>"application/json"},
|
98
|
+
["{\"message\":\"could not find command file: spec/e2e/app_commands/load_sample.rb\"}"]])
|
97
99
|
expect(command_executor).to_not have_received(:perform)
|
98
100
|
end
|
99
101
|
end
|
@@ -102,7 +104,7 @@ RSpec.describe CypressOnRails::Middleware do
|
|
102
104
|
context '"Other paths"' do
|
103
105
|
it 'runs app' do
|
104
106
|
aggregate_failures do
|
105
|
-
%w(/ /
|
107
|
+
%w(/ /__e2e__/login command /e2e_command /).each do |path|
|
106
108
|
env['PATH_INFO'] = path
|
107
109
|
|
108
110
|
response = subject.call(env)
|
@@ -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
|
|