cypress-on-rails 0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bdfc04b2cd587e4d0e67879f830117416b679968
4
+ data.tar.gz: '0784e1cd91281ed2f668ee5ea9dc3b89560a4ef3'
5
+ SHA512:
6
+ metadata.gz: 6c186111c70d54b2610ff0b18fee74f6fc14c90376c0bb1bb0cc0fd2af998595035b5c7201d85a0e35f3045cf67f9cf8f3374a1988b8637d108a254ad4da852a
7
+ data.tar.gz: 1e4c83231e310fada2ad93aa480ae5b1571f55077ce5b57edd90e4bac749fe204efaacf3b21b689b19d6f9f4038a447f1107e1cd394c75474950d07aa727d33f
@@ -0,0 +1 @@
1
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
3
+
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cypress-on-rails (0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rspec (3.7.0)
11
+ rspec-core (~> 3.7.0)
12
+ rspec-expectations (~> 3.7.0)
13
+ rspec-mocks (~> 3.7.0)
14
+ rspec-core (3.7.0)
15
+ rspec-support (~> 3.7.0)
16
+ rspec-expectations (3.7.0)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.7.0)
19
+ rspec-mocks (3.7.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.7.0)
22
+ rspec-support (3.7.0)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ cypress-on-rails!
29
+ rspec
30
+
31
+ BUNDLED WITH
32
+ 1.15.4
@@ -0,0 +1 @@
1
+ # cypress-on-rails
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'cypress'
3
+ Cypress::Server.new(ARGV).run
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
3
+ require "cypress/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "cypress-on-rails"
7
+ s.version = Cypress::VERSION
8
+ s.author = "miceportal team"
9
+ s.email = "info@miceportal.de"
10
+ s.homepage = "http://github.com/konvenit/cypress-on-rails"
11
+ s.summary = "Integrates cypress with rails"
12
+ s.description = "Integrates cypress with rails"
13
+ s.rubyforge_project = s.name
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+ s.add_dependency 'activesupport'
19
+ s.add_dependency 'selenium-webdriver' # to be replaced
20
+ s.add_development_dependency 'rspec'
21
+ end
@@ -0,0 +1 @@
1
+ require_relative './cypress'
@@ -0,0 +1,19 @@
1
+ require 'active_support/dependencies/autoload'
2
+
3
+ module Cypress
4
+ extend ActiveSupport::Autoload
5
+
6
+ autoload :Server, 'cypress/server'
7
+ autoload :CallbackServer, 'cypress/callback_server'
8
+ autoload :Runner, 'cypress/runner'
9
+ autoload :ScenarioBank, 'cypress/scenario_bank'
10
+ autoload :Configuration, 'cypress/configuration'
11
+
12
+ def self.configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def self.configure(&block)
17
+ yield configuration if block_given?
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ module Cypress
2
+ class CallbackServer
3
+ attr_reader :port
4
+ def initialize(owner)
5
+ @port = 9293
6
+ @webrick = WEBrick::HTTPServer.new(:Port => port)
7
+ @webrick.mount_proc '/' do |req, res|
8
+ owner.run_command JSON.parse(req.body)
9
+ res.body = ''
10
+ end
11
+ end
12
+
13
+ def start
14
+ @webrick.start
15
+ end
16
+
17
+ def shutdown
18
+ @webrick.shutdown
19
+ end
20
+
21
+ def callback_url
22
+ "http://localhost:9293"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ module Cypress
2
+ class Configuration
3
+ attr_accessor :test_framework, :db_resetter, :cache_classes
4
+
5
+ def initialize
6
+ @test_framework = :rspec
7
+ @db_resetter = :database_cleaner
8
+ @before = proc {}
9
+ end
10
+
11
+ def before(&block)
12
+ if block_given?
13
+ @before = block
14
+ else
15
+ @before
16
+ end
17
+ end
18
+
19
+ def cache_classes
20
+ !! @cache_classes
21
+ end
22
+
23
+ def disable_class_caching
24
+ if @cache_classes.nil?
25
+ @cache_classes = false
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ module Cypress
2
+ class Runner
3
+ def initialize(owner, callback_url)
4
+ @owner = owner
5
+ @callback_url = callback_url
6
+ end
7
+
8
+ def run(server_port)
9
+ Open3.popen2(*cypress_cli(server_port)) do |sin, sout, status|
10
+ sout.each_line do |line|
11
+ puts "CYPRESS: #{line}"
12
+ end
13
+ end
14
+ end
15
+
16
+ private
17
+ def cypress_cli(server_port)
18
+ result = ['yarn', 'run']
19
+ result += ['cypress', @owner.mode]
20
+ result += ['--env', "SERVER_PORT=#{server_port},CALLBACK=#{@callback_url}"]
21
+ result += ['-c', 'videosFolder=spec/cypress/videos,fixturesFolder=spec/cypress/fixtures,integrationFolder=spec/cypress/integrations/,supportFile=spec/cypress/support/setup.js']
22
+ result
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ module Cypress
2
+ class ScenarioBank
3
+ def initialize
4
+ @scenarios = {}
5
+ end
6
+
7
+ def boot
8
+ if Cypress.configuration.test_framework == :rspec
9
+ require 'rspec/rails'
10
+ extend RSpec::Mocks::ExampleMethods
11
+ end
12
+ end
13
+
14
+ def load
15
+ Dir['./spec/cypress/scenarios/**/*.rb'].each do |f|
16
+ instance_eval(File.read(f), f)
17
+ end
18
+ end
19
+
20
+ def scenario(name, &block)
21
+ @scenarios[name] = block
22
+ end
23
+
24
+ def [](name)
25
+ @scenarios[name.to_sym]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,75 @@
1
+ require 'webrick'
2
+ require 'json'
3
+
4
+ module Cypress
5
+ class Server
6
+ def initialize(args)
7
+ @args = args
8
+ @callback_server = CallbackServer.new(self)
9
+ @runner = Runner.new self, @callback_server.callback_url
10
+ @scenario_bank = ScenarioBank.new
11
+ end
12
+
13
+ def mode
14
+ if @args.first == 'run'
15
+ 'run'
16
+ else
17
+ 'open'
18
+ end
19
+ end
20
+
21
+ def run
22
+ load_cypress_helper
23
+ server_port = boot_rails
24
+ @scenario_bank.boot
25
+
26
+ @callback_thread = Thread.new { @callback_server.start }
27
+ @runner_thread = Thread.new { @runner.run server_port }
28
+ @runner_thread.join
29
+
30
+ @callback_server.shutdown
31
+ end
32
+
33
+ def run_command(command)
34
+ @scenario_bank.load
35
+
36
+ if command['scenario'] and (block = @scenario_bank[command['scenario']])
37
+ reset_rspec if configuration.test_framework == :rspec
38
+ call_database_cleaner if configuration.db_resetter == :database_cleaner
39
+ configuration.before.call
40
+
41
+ block.call
42
+ end
43
+ end
44
+
45
+ private
46
+ def configuration
47
+ Cypress.configuration
48
+ end
49
+
50
+ def boot_rails
51
+ ENV['RAILS_ENV'] ||= 'test'
52
+ require './config/environment'
53
+ require 'capybara/rails'
54
+
55
+ Capybara.current_driver = :selenium # oh, the irony....
56
+ Capybara.current_session.server.port
57
+ end
58
+
59
+ def load_cypress_helper
60
+ require "./spec/cypress/cypress_helper"
61
+ configuration.disable_class_caching if mode == 'open'
62
+ end
63
+
64
+ def reset_rspec
65
+ RSpec::Mocks.teardown
66
+ RSpec::Mocks.setup
67
+ end
68
+
69
+ def call_database_cleaner
70
+ require 'database_cleaner'
71
+ DatabaseCleaner.strategy = :truncation
72
+ DatabaseCleaner.clean
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module Cypress
2
+ VERSION = "0.1".freeze
3
+ end
@@ -0,0 +1,52 @@
1
+ module Cypress
2
+ class InstallGenerator < Rails::Generators::Base
3
+ def install
4
+ empty_directory "spec/cypress"
5
+ empty_directory "spec/cypress/integrations"
6
+ empty_directory "spec/cypress/scenarios"
7
+ empty_directory "spec/cypress/support"
8
+
9
+ create_file "spec/cypress/cypress_helper.rb", <<-FILE
10
+ Cypress.configure do |c|
11
+ # change this to nil, if you are not using RSpec Mocks
12
+ c.test_framework = :rspec
13
+
14
+ # change this to nil, if you are not using DatabaseCleaner
15
+ c.db_resetter = :database_cleaner
16
+
17
+ c.before do
18
+ # this is called when you call cy.setupScenario
19
+ # use it to reset your application state
20
+ end
21
+ end
22
+ FILE
23
+
24
+ create_file "spec/cypress/integrations/simple_spec.js", <<-FILE
25
+ describe('My First Test', function() {
26
+ it('visit root', function() {
27
+ // This calls to the backend to prepare the application state
28
+ // see the scenarios directory
29
+ cy.setupScenario('basic')
30
+
31
+ // The application unter test is available at SERVER_PORT
32
+ cy.visit('http://localhost:'+Cypress.env("SERVER_PORT"))
33
+ })
34
+ })
35
+ FILE
36
+
37
+ create_file "spec/cypress/scenarios/basic.rb", <<-FILE
38
+ scenario :basic do
39
+ # You can setup your Rails state here
40
+ # MyModel.create name: 'something'
41
+ end
42
+ FILE
43
+
44
+ create_file "spec/cypress/integrations/simple_spec.js", <<-FILE
45
+ // dont remove this command
46
+ Cypress.Commands.add('setupScenario', function(name) {
47
+ Cypress.log({ message: name })
48
+ cy.request('POST', Cypress.env("CALLBACK"), JSON.stringify({ scenario: name }))
49
+ });
50
+ FILE
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cypress-on-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - miceportal team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: selenium-webdriver
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Integrates cypress with rails
56
+ email: info@miceportal.de
57
+ executables:
58
+ - cypress
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - README.md
66
+ - bin/cypress
67
+ - cypress-on-rails.gemspec
68
+ - lib/cypress-on-rails.rb
69
+ - lib/cypress.rb
70
+ - lib/cypress/callback_server.rb
71
+ - lib/cypress/configuration.rb
72
+ - lib/cypress/runner.rb
73
+ - lib/cypress/scenario_bank.rb
74
+ - lib/cypress/server.rb
75
+ - lib/cypress/version.rb
76
+ - lib/generators/install_generator.rb
77
+ homepage: http://github.com/konvenit/cypress-on-rails
78
+ licenses: []
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project: cypress-on-rails
96
+ rubygems_version: 2.6.11
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Integrates cypress with rails
100
+ test_files: []