-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cypress js plugin and vcr integration (#103)
- Loading branch information
1 parent
a35dcd1
commit 17cd554
Showing
165 changed files
with
454 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,7 @@ spec/examples.txt | |
spec/test.log | ||
pkg/*.gem | ||
vendor/bundle | ||
.vscode | ||
.vscode | ||
node_modules | ||
package-lock.json | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'json' | ||
require 'rack' | ||
require 'cypress_on_rails/configuration' | ||
|
||
module CypressOnRails | ||
module MiddlewareConfig | ||
protected | ||
|
||
def configuration | ||
CypressOnRails.configuration | ||
end | ||
|
||
def logger | ||
configuration.logger | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'json' | ||
require 'rack' | ||
require 'cypress_on_rails/middleware_config' | ||
|
||
module CypressOnRails | ||
# Middleware to handle vcr | ||
class VCRMiddleware | ||
include MiddlewareConfig | ||
|
||
def initialize(app, vcr = nil) | ||
@app = app | ||
@vcr = vcr | ||
end | ||
|
||
def call(env) | ||
request = Rack::Request.new(env) | ||
if request.path.start_with?('/__cypress__/vcr/insert') | ||
configuration.tagged_logged { handle_insert(request) } | ||
elsif request.path.start_with?('/__cypress__/vcr/eject') | ||
configuration.tagged_logged { handle_eject } | ||
else | ||
@app.call(env) | ||
end | ||
end | ||
|
||
private | ||
|
||
def handle_insert(req) | ||
body = JSON.parse(req.body.read) | ||
logger.info "vcr insert cassette: #{body}" | ||
cassette_name = body[0] | ||
options = (body[1] || {}).symbolize_keys | ||
options[:record] = options[:record].to_sym if options[:record] | ||
options[:match_requests_on] = options[:match_requests_on].map(&:to_sym) if options[:match_requests_on] | ||
options[:serialize_with] = options[:serialize_with].to_sym if options[:serialize_with] | ||
options[:persist_with] = options[:persist_with].to_sym if options[:persist_with] | ||
vcr.insert_cassette(cassette_name, options) | ||
[201, {'Content-Type' => 'application/json'}, [{'message': 'OK'}.to_json]] | ||
rescue LoadError, ArgumentError => e | ||
[501, {'Content-Type' => 'application/json'}, [{'message': e.message}.to_json]] | ||
end | ||
|
||
def handle_eject | ||
logger.info "vcr eject cassette" | ||
vcr.eject_cassette | ||
[201, {'Content-Type' => 'application/json'}, [{'message': 'OK'}.to_json]] | ||
rescue LoadError, ArgumentError => e | ||
[501, {'Content-Type' => 'application/json'}, [{'message': e.message}.to_json]] | ||
end | ||
|
||
def vcr | ||
return @vcr if @vcr | ||
require 'vcr' | ||
VCR.configure do |config| | ||
config.cassette_library_dir = "#{configuration.cypress_folder}/fixtures/vcr_cassettes" | ||
end | ||
@vcr = VCR | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...tors/cypress_on_rails/templates/spec/cypress/integration/rails_examples/using_vcr_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
describe('Rails Other examples', function() { | ||
it('Inserting a cassette', function() { | ||
cy.app('clean') // have a look at cypress/app_commands/clean.rb | ||
|
||
cy.vcr_insert_cassette('cats', { record: "new_episodes" }) | ||
cy.visit('/using_vcr/index') | ||
|
||
cy.get('a').contains('Cats').click() | ||
cy.contains('Wikipedia has a recording of a cat meowing, because why not?') | ||
|
||
cy.vcr_eject_cassette(); | ||
|
||
cy.vcr_insert_cassette('cats') | ||
cy.visit('/using_vcr/record_cats') | ||
cy.contains('Wikipedia has a recording of a cat meowing, because why not?') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// export a function | ||
module.exports = (on, config) => { | ||
// configure plugins here | ||
} |
Oops, something went wrong.