cypress_rails 0.3.0 → 0.4.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
  SHA1:
3
- metadata.gz: d9622fc9e2ab6e48541a371469cfc42bbb523daf
4
- data.tar.gz: b7321531f8e5cc10cfd62c08c49a4e6da498d32c
3
+ metadata.gz: 17a9c9a3af4b4dcde29ffb4b27780a5e3d42aea4
4
+ data.tar.gz: 0ad42a978ebd4448c61fc059eccf48cee48b7df1
5
5
  SHA512:
6
- metadata.gz: d11841e68726c53d368fd0c9917763de6b33b86cdf23d7676d2f3b745138615ad0c3bca154e072ca78d72e7f455cde0594a669179b0354aa09dcae07cc32e08e
7
- data.tar.gz: 1ae36bfde43f2a76aef98393f14bb4c5f5cad9ee75d3bdd0122d1733461bc0e52ccfe78fac7419a560005555d34594acd5ffa455ee80bcb3865e5708ee233cdf
6
+ metadata.gz: 12d3a9c86ffb64482bc9280d135dae376b082004686acf8d0280976023f8a647157be98a8c6377a78d50b050e06327234d5943fdd63d28faf03bfb1bfb239fd1
7
+ data.tar.gz: 85691194ee4d77df74816d732d38346eeb7d9a0a701ffe4383e603d15024a7b128818cd9a637ce4353ada7a40a5f524acc8b9f52e8d87cb1416521c9f9f14688
data/ChangeLog.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 0.4.0 / 2018-05-17
2
+
3
+ * Integrate the gem with Rails and hook up a middleware for:
4
+ * reseting the database
5
+ * calling "seed" files
6
+ * Added configuration object with `before_each` option which takes a block of code to be executed
7
+ before each example
8
+
1
9
  ### 0.3.0 / 2018-05-16
2
10
 
3
11
  * Added more options to the CLI
@@ -30,6 +30,7 @@ Gem::Specification.new do |gem|
30
30
  gem.require_paths = ["lib"]
31
31
 
32
32
  gem.add_dependency "thor", "~> 0.20.0"
33
+ gem.add_dependency "railties", ">= 4.2.0"
33
34
  gem.add_development_dependency "bundler", "~> 1.10"
34
35
  gem.add_development_dependency "codeclimate-test-reporter", "~> 0.1"
35
36
  gem.add_development_dependency "pry", "~> 0.11.3"
data/lib/cypress_rails.rb CHANGED
@@ -1,3 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
  #
3
3
  require "cypress_rails/version"
4
+ require "cypress_rails/railtie"
5
+ require "cypress_rails/configuration"
6
+
7
+ module CypressRails
8
+
9
+ def seeds(name)
10
+ instance_eval File.read("spec/cypress/seeds/#{name}.rb")
11
+ end
12
+ module_function :seeds
13
+ end
@@ -0,0 +1,18 @@
1
+ module CypressRails
2
+ class << self
3
+ attr_accessor :configuration
4
+ end
5
+
6
+ def self.configure
7
+ self.configuration ||= Configuration.new
8
+ yield(configuration)
9
+ end
10
+
11
+ class Configuration
12
+ attr_accessor :before_each
13
+
14
+ def initialize
15
+ @before_each = -> {}
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CypressRails
4
+ class Middleware
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ request = Rack::Request.new(env)
11
+
12
+ if cypress_rails_url?(request.path)
13
+ setup! if setup_url?(request.path)
14
+ seed!(request) if seed_url?(request.path)
15
+ return [
16
+ 201,
17
+ { "Content-Type" => "text/html" },
18
+ [""]
19
+ ]
20
+ end
21
+
22
+ @app.call(env)
23
+ end
24
+
25
+ private
26
+
27
+ def cypress_rails_url?(path)
28
+ path.starts_with?("/__cypress_rails__")
29
+ end
30
+
31
+ def setup_url?(path)
32
+ path.gsub("/__cypress_rails__/", "") == "setup"
33
+ end
34
+
35
+ def seed_url?(path)
36
+ path.gsub("/__cypress_rails__/", "") == "seeds"
37
+ end
38
+
39
+ def setup!
40
+ reset_db!
41
+ end
42
+
43
+ def seed!(request)
44
+ body = JSON.parse(request.body.read)
45
+ CypressRails.seeds(body.fetch("seed")).call
46
+ end
47
+
48
+ def reset_db!
49
+ CypressRails.configuration.before_each.call
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/railtie"
4
+ require "cypress_rails/middleware"
5
+
6
+ module CypressRails
7
+ class Railtie < Rails::Railtie
8
+ initializer :setup_cypress do |app|
9
+ app.middleware.use Middleware
10
+ end
11
+ end
12
+ end
@@ -15,6 +15,7 @@ module CypressRails
15
15
  {
16
16
  "CYPRESS_app_host" => host,
17
17
  "CYPRESS_app_port" => port.to_s,
18
+ "CYPRESS_baseUrl" => "http://#{host}:#{port}"
18
19
  },
19
20
  [bin_path, "run", "-P #{tests_path}"].join(" "),
20
21
  out: output,
@@ -30,6 +31,7 @@ module CypressRails
30
31
  {
31
32
  "CYPRESS_app_host" => host,
32
33
  "CYPRESS_app_port" => port.to_s,
34
+ "CYPRESS_baseUrl" => "http://#{host}:#{port}"
33
35
  },
34
36
  [bin_path, "open", "-P #{tests_path}"].join(" "),
35
37
  out: output,
@@ -2,5 +2,5 @@
2
2
 
3
3
  module CypressRails
4
4
  # cypress_rails version
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cypress_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Szymon Szeliga
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.20.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: railties
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.2.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -186,6 +200,9 @@ files:
186
200
  - cypress_rails.gemspec
187
201
  - lib/cypress_rails.rb
188
202
  - lib/cypress_rails/cli.rb
203
+ - lib/cypress_rails/configuration.rb
204
+ - lib/cypress_rails/middleware.rb
205
+ - lib/cypress_rails/railtie.rb
189
206
  - lib/cypress_rails/runner.rb
190
207
  - lib/cypress_rails/server.rb
191
208
  - lib/cypress_rails/version.rb