diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 23f9fbf..a1227fc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,10 +8,10 @@ jobs: strategy: matrix: - ruby-version: ['2.7', '3.0'] + ruby-version: ['3.0', '3.3'] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cad6dd..286116c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # CHANGELOG +## 0.7.1 +* Add Rack 3.1 support [#163](https://github.com/testdouble/cypress-rails/pull/163) + +## 0.7.0 +git +* Add a `CYPRESS_RAILS_CYPRESS_DIR` option for cases where +the cypress tests live outside the CYPRESS_RAILS_DIR [#159](https://github.com/testdouble/cypress-rails/pull/159) + ## 0.6.1 * Fix a deprecation warning in Rails diff --git a/Gemfile.lock b/Gemfile.lock index a5aace4..e3d95e2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,98 +1,143 @@ PATH remote: . specs: - cypress-rails (0.6.1) + cypress-rails (0.7.1) puma (>= 3.8.0) railties (>= 5.2.0) GEM remote: https://rubygems.org/ specs: - actionpack (7.0.6) - actionview (= 7.0.6) - activesupport (= 7.0.6) - rack (~> 2.0, >= 2.2.4) + actionpack (7.1.3) + actionview (= 7.1.3) + activesupport (= 7.1.3) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actionview (7.0.6) - activesupport (= 7.0.6) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actionview (7.1.3) + activesupport (= 7.1.3) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activesupport (7.0.6) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activesupport (7.1.3) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) ast (2.4.2) + base64 (0.2.0) + bigdecimal (3.1.6) builder (3.2.4) - concurrent-ruby (1.2.2) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) crass (1.0.6) + drb (2.2.0) + ruby2_keywords erubi (1.12.0) i18n (1.14.1) concurrent-ruby (~> 1.0) - loofah (2.21.3) + io-console (0.7.2) + irb (1.13.1) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + json (2.7.1) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) - method_source (1.0.0) - mini_portile2 (2.8.2) - minitest (5.15.0) - nio4r (2.5.9) - nokogiri (1.15.3) - mini_portile2 (~> 2.8.2) + minitest (5.22.2) + mutex_m (0.2.0) + nio4r (2.7.0) + nokogiri (1.16.2) racc (~> 1.4) - parallel (1.22.1) - parser (3.1.2.0) + parallel (1.24.0) + parser (3.3.0.5) ast (~> 2.4.1) - puma (6.3.0) + racc + psych (5.1.2) + stringio + puma (6.4.2) nio4r (~> 2.0) - racc (1.7.1) - rack (2.2.7) + racc (1.7.3) + rack (3.1.7) + rack-session (2.0.0) + rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rails-dom-testing (2.1.1) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) rails-html-sanitizer (1.6.0) loofah (~> 2.21) nokogiri (~> 1.14) - railties (7.0.6) - actionpack (= 7.0.6) - activesupport (= 7.0.6) - method_source + railties (7.1.3) + actionpack (= 7.1.3) + activesupport (= 7.1.3) + irb + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) rainbow (3.1.1) - rake (13.0.6) - regexp_parser (2.4.0) - rexml (3.2.5) - rubocop (1.29.1) + rake (13.1.0) + rdoc (6.6.3.1) + psych (>= 4.0.0) + regexp_parser (2.9.0) + reline (0.5.7) + io-console (~> 0.5) + rexml (3.2.6) + rubocop (1.59.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.1.0.0) + parser (>= 3.2.2.4) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.17.0, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.18.0) - parser (>= 3.1.1.0) - rubocop-performance (1.13.3) - rubocop (>= 1.7.0, < 2.0) - rubocop-ast (>= 0.4.0) - ruby-progressbar (1.11.0) - standard (1.12.1) - rubocop (= 1.29.1) - rubocop-performance (= 1.13.3) - thor (1.2.2) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.30.0) + parser (>= 3.2.1.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + standard (1.33.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.59.0) + standard-custom (~> 1.0.0) + standard-performance (~> 1.3) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.3.1) + lint_roller (~> 1.1) + rubocop-performance (~> 1.20.2) + stringio (3.1.1) + thor (1.3.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.1.0) - zeitwerk (2.6.8) + unicode-display_width (2.5.0) + webrick (1.8.1) + zeitwerk (2.6.13) PLATFORMS ruby diff --git a/README.md b/README.md index e41adb7..3c876b1 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,8 @@ preferred environment variables project-wide using a tool like [dotenv](https://github.com/bkeepers/dotenv). -* **CYPRESS_RAILS_DIR** (default: `Dir.pwd`) the directory of your project +* **CYPRESS_RAILS_DIR** (default: `Dir.pwd`) the directory of your Rails project +* **CYPRESS_RAILS_CYPRESS_DIR** (default: _same value as `rails_dir`_) the directory of your Cypress project * **CYPRESS_RAILS_HOST** (default: `"127.0.0.1"`) the hostname to bind to * **CYPRESS_RAILS_PORT** (default: _a random available port_) the port to run the Rails test server on diff --git a/example/.gitignore b/example/.gitignore index d1d7448..5a5721c 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -10,6 +10,8 @@ # Ignore the default SQLite database. /db/*.sqlite3 /db/*.sqlite3-journal +/db/*.sqlite3-shm +/db/*.sqlite3-wal # Ignore all logfiles and tempfiles. /log/* diff --git a/example/Gemfile.lock b/example/Gemfile.lock index 6b82047..0e8e2b7 100644 --- a/example/Gemfile.lock +++ b/example/Gemfile.lock @@ -1,169 +1,202 @@ PATH remote: .. specs: - cypress-rails (0.6.1) + cypress-rails (0.7.1) puma (>= 3.8.0) railties (>= 5.2.0) GEM remote: https://rubygems.org/ specs: - actioncable (7.0.3) - actionpack (= 7.0.3) - activesupport (= 7.0.3) + actioncable (7.1.3) + actionpack (= 7.1.3) + activesupport (= 7.1.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.3) - actionpack (= 7.0.3) - activejob (= 7.0.3) - activerecord (= 7.0.3) - activestorage (= 7.0.3) - activesupport (= 7.0.3) + zeitwerk (~> 2.6) + actionmailbox (7.1.3) + actionpack (= 7.1.3) + activejob (= 7.1.3) + activerecord (= 7.1.3) + activestorage (= 7.1.3) + activesupport (= 7.1.3) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.3) - actionpack (= 7.0.3) - actionview (= 7.0.3) - activejob (= 7.0.3) - activesupport (= 7.0.3) + actionmailer (7.1.3) + actionpack (= 7.1.3) + actionview (= 7.1.3) + activejob (= 7.1.3) + activesupport (= 7.1.3) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp - rails-dom-testing (~> 2.0) - actionpack (7.0.3) - actionview (= 7.0.3) - activesupport (= 7.0.3) - rack (~> 2.0, >= 2.2.0) + rails-dom-testing (~> 2.2) + actionpack (7.1.3) + actionview (= 7.1.3) + activesupport (= 7.1.3) + nokogiri (>= 1.8.5) + racc + rack (>= 2.2.4) + rack-session (>= 1.0.1) rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (7.0.3) - actionpack (= 7.0.3) - activerecord (= 7.0.3) - activestorage (= 7.0.3) - activesupport (= 7.0.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + actiontext (7.1.3) + actionpack (= 7.1.3) + activerecord (= 7.1.3) + activestorage (= 7.1.3) + activesupport (= 7.1.3) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.3) - activesupport (= 7.0.3) + actionview (7.1.3) + activesupport (= 7.1.3) builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (7.0.3) - activesupport (= 7.0.3) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (7.1.3) + activesupport (= 7.1.3) globalid (>= 0.3.6) - activemodel (7.0.3) - activesupport (= 7.0.3) - activerecord (7.0.3) - activemodel (= 7.0.3) - activesupport (= 7.0.3) - activestorage (7.0.3) - actionpack (= 7.0.3) - activejob (= 7.0.3) - activerecord (= 7.0.3) - activesupport (= 7.0.3) + activemodel (7.1.3) + activesupport (= 7.1.3) + activerecord (7.1.3) + activemodel (= 7.1.3) + activesupport (= 7.1.3) + timeout (>= 0.4.0) + activestorage (7.1.3) + actionpack (= 7.1.3) + activejob (= 7.1.3) + activerecord (= 7.1.3) + activesupport (= 7.1.3) marcel (~> 1.0) - mini_mime (>= 1.1.0) - activesupport (7.0.3) + activesupport (7.1.3) + base64 + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb i18n (>= 1.6, < 2) minitest (>= 5.1) + mutex_m tzinfo (~> 2.0) - bootsnap (1.11.1) + base64 (0.2.0) + bigdecimal (3.1.6) + bootsnap (1.18.3) msgpack (~> 1.2) builder (3.2.4) - concurrent-ruby (1.1.10) + concurrent-ruby (1.2.3) + connection_pool (2.4.1) crass (1.0.6) - digest (3.1.0) - erubi (1.10.0) - globalid (1.0.0) - activesupport (>= 5.0) - i18n (1.10.0) + date (3.3.4) + drb (2.2.0) + ruby2_keywords + erubi (1.12.0) + globalid (1.2.1) + activesupport (>= 6.1) + i18n (1.14.1) concurrent-ruby (~> 1.0) - loofah (2.18.0) + io-console (0.7.2) + irb (1.11.2) + rdoc + reline (>= 0.4.2) + loofah (2.22.0) crass (~> 1.0.2) - nokogiri (>= 1.5.9) - mail (2.7.1) + nokogiri (>= 1.12.0) + mail (2.8.1) mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp marcel (1.0.2) - method_source (1.0.0) - mini_mime (1.1.2) - mini_portile2 (2.8.0) - minitest (5.15.0) - msgpack (1.5.1) - net-imap (0.2.3) - digest + mini_mime (1.1.5) + mini_portile2 (2.8.5) + minitest (5.22.2) + msgpack (1.7.2) + mutex_m (0.2.0) + net-imap (0.4.10) + date net-protocol - strscan - net-pop (0.1.1) - digest + net-pop (0.1.2) net-protocol + net-protocol (0.2.2) timeout - net-protocol (0.1.3) - timeout - net-smtp (0.3.1) - digest + net-smtp (0.4.0.1) net-protocol - timeout - nio4r (2.5.8) - nokogiri (1.13.6) - mini_portile2 (~> 2.8.0) + nio4r (2.7.0) + nokogiri (1.16.2) + mini_portile2 (~> 2.8.2) racc (~> 1.4) - puma (5.6.4) + psych (5.1.2) + stringio + puma (6.4.2) nio4r (~> 2.0) - racc (1.6.0) - rack (2.2.3) - rack-proxy (0.7.2) + racc (1.7.3) + rack (3.1.7) + rack-proxy (0.7.7) rack - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (7.0.3) - actioncable (= 7.0.3) - actionmailbox (= 7.0.3) - actionmailer (= 7.0.3) - actionpack (= 7.0.3) - actiontext (= 7.0.3) - actionview (= 7.0.3) - activejob (= 7.0.3) - activemodel (= 7.0.3) - activerecord (= 7.0.3) - activestorage (= 7.0.3) - activesupport (= 7.0.3) + rack-session (2.0.0) + rack (>= 3.0.0) + rack-test (2.1.0) + rack (>= 1.3) + rackup (2.1.0) + rack (>= 3) + webrick (~> 1.8) + rails (7.1.3) + actioncable (= 7.1.3) + actionmailbox (= 7.1.3) + actionmailer (= 7.1.3) + actionpack (= 7.1.3) + actiontext (= 7.1.3) + actionview (= 7.1.3) + activejob (= 7.1.3) + activemodel (= 7.1.3) + activerecord (= 7.1.3) + activestorage (= 7.1.3) + activesupport (= 7.1.3) bundler (>= 1.15.0) - railties (= 7.0.3) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + railties (= 7.1.3) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) - loofah (~> 2.3) - railties (7.0.3) - actionpack (= 7.0.3) - activesupport (= 7.0.3) - method_source + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) + railties (7.1.3) + actionpack (= 7.1.3) + activesupport (= 7.1.3) + irb + rackup (>= 1.0.0) rake (>= 12.2) - thor (~> 1.0) - zeitwerk (~> 2.5) - rake (13.0.6) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rake (13.1.0) + rdoc (6.6.2) + psych (>= 4.0.0) + reline (0.4.2) + io-console (~> 0.5) + ruby2_keywords (0.0.5) semantic_range (3.0.0) - sqlite3 (1.4.2) - strscan (3.0.3) - thor (1.2.1) - timeout (0.2.0) - tzinfo (2.0.4) + sqlite3 (1.7.2) + mini_portile2 (~> 2.8.0) + stringio (3.1.0) + thor (1.3.0) + timeout (0.4.1) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) - webpacker (5.4.3) + webpacker (5.4.4) activesupport (>= 5.2) rack-proxy (>= 0.6.1) railties (>= 5.2) semantic_range (>= 2.3.0) - websocket-driver (0.7.5) + webrick (1.8.1) + websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.5.4) + zeitwerk (2.6.13) PLATFORMS ruby diff --git a/exe/cypress-rails b/exe/cypress-rails index fe13df6..5ee28ea 100755 --- a/exe/cypress-rails +++ b/exe/cypress-rails @@ -3,7 +3,7 @@ ENV["RAILS_ENV"] ||= "test" require "pathname" require "cypress-rails" -require Pathname.new(CypressRails::Config.new.dir).join("config/environment") +require Pathname.new(CypressRails::Config.new.rails_dir).join("config/environment") command = ARGV[0] case command diff --git a/lib/cypress-rails/config.rb b/lib/cypress-rails/config.rb index 19f0376..6677f58 100644 --- a/lib/cypress-rails/config.rb +++ b/lib/cypress-rails/config.rb @@ -2,17 +2,19 @@ module CypressRails class Config - attr_accessor :dir, :host, :port, :base_path, :transactional_server, :cypress_cli_opts + attr_accessor :rails_dir, :cypress_dir, :host, :port, :base_path, :transactional_server, :cypress_cli_opts def initialize( - dir: Env.fetch("CYPRESS_RAILS_DIR", default: Dir.pwd), + rails_dir: Env.fetch("CYPRESS_RAILS_DIR", default: Dir.pwd), + cypress_dir: Env.fetch("CYPRESS_RAILS_CYPRESS_DIR", default: rails_dir), host: Env.fetch("CYPRESS_RAILS_HOST", default: "127.0.0.1"), port: Env.fetch("CYPRESS_RAILS_PORT"), base_path: Env.fetch("CYPRESS_RAILS_BASE_PATH", default: "/"), transactional_server: Env.fetch("CYPRESS_RAILS_TRANSACTIONAL_SERVER", type: :boolean, default: true), cypress_cli_opts: Env.fetch("CYPRESS_RAILS_CYPRESS_OPTS", default: "") ) - @dir = dir + @rails_dir = rails_dir + @cypress_dir = cypress_dir @host = host @port = port @base_path = base_path @@ -25,7 +27,8 @@ def to_s cypress-rails configuration: ============================ - CYPRESS_RAILS_DIR.....................#{dir.inspect} + CYPRESS_RAILS_DIR.....................#{rails_dir.inspect} + CYPRESS_RAILS_CYPRESS_DIR.............#{cypress_dir.inspect} CYPRESS_RAILS_HOST....................#{host.inspect} CYPRESS_RAILS_PORT....................#{port.inspect} CYPRESS_RAILS_BASE_PATH...............#{base_path.inspect} diff --git a/lib/cypress-rails/finds_bin.rb b/lib/cypress-rails/finds_bin.rb index 09774d9..d36a618 100644 --- a/lib/cypress-rails/finds_bin.rb +++ b/lib/cypress-rails/finds_bin.rb @@ -4,8 +4,8 @@ module CypressRails class FindsBin LOCAL_PATH = "node_modules/.bin/cypress" - def call(dir = Dir.pwd) - local_path = Pathname.new(dir).join(LOCAL_PATH) + def call(cypress_dir = Dir.pwd) + local_path = Pathname.new(cypress_dir).join(LOCAL_PATH) if File.exist?(local_path) local_path else diff --git a/lib/cypress-rails/init.rb b/lib/cypress-rails/init.rb index 66d0083..1a4fcae 100644 --- a/lib/cypress-rails/init.rb +++ b/lib/cypress-rails/init.rb @@ -19,8 +19,8 @@ class Init }) JS - def call(dir = Dir.pwd) - config_path = File.join(dir, "cypress.config.js") + def call(cypress_dir = Config.new.cypress_dir) + config_path = File.join(cypress_dir, "cypress.config.js") if !File.exist?(config_path) File.write(config_path, DEFAULT_CONFIG) puts "Cypress config initialized in `#{config_path}'" diff --git a/lib/cypress-rails/launches_cypress.rb b/lib/cypress-rails/launches_cypress.rb index aeb0a34..1ee6bc4 100644 --- a/lib/cypress-rails/launches_cypress.rb +++ b/lib/cypress-rails/launches_cypress.rb @@ -14,7 +14,7 @@ def initialize end def call(command, config) - puts config.to_s + puts config @initializer_hooks.run(:before_server_start) if config.transactional_server @manages_transactions.begin_transaction @@ -24,12 +24,12 @@ def call(command, config) port: config.port, transactional_server: config.transactional_server ) - bin = @finds_bin.call(config.dir) + bin = @finds_bin.call(config.cypress_dir) set_exit_hooks!(config) command = <<~EXEC - CYPRESS_BASE_URL="http://#{server.host}:#{server.port}#{config.base_path}" "#{bin}" #{command} --project "#{config.dir}" #{config.cypress_cli_opts} + CYPRESS_BASE_URL="http://#{server.host}:#{server.port}#{config.base_path}" "#{bin}" #{command} --project "#{config.cypress_dir}" #{config.cypress_cli_opts} EXEC puts "\nLaunching Cypress…\n$ #{command}\n" diff --git a/lib/cypress-rails/server.rb b/lib/cypress-rails/server.rb index ab802de..92fcee4 100644 --- a/lib/cypress-rails/server.rb +++ b/lib/cypress-rails/server.rb @@ -53,7 +53,7 @@ def responsive? res = @checker.request { |http| http.get("/__identify__") } - return res.body == app.object_id.to_s if res.is_a?(Net::HTTPSuccess) || res.is_a?(Net::HTTPRedirection) + res.body == app.object_id.to_s if res.is_a?(Net::HTTPSuccess) || res.is_a?(Net::HTTPRedirection) rescue SystemCallError, Net::ReadTimeout, OpenSSL::SSL::SSLError false end diff --git a/lib/cypress-rails/server/puma.rb b/lib/cypress-rails/server/puma.rb index fcda07b..a90397e 100644 --- a/lib/cypress-rails/server/puma.rb +++ b/lib/cypress-rails/server/puma.rb @@ -10,7 +10,8 @@ def self.create(app, port, host) default_options = {Host: host, Port: port, Threads: "0:4", workers: 0, daemon: false} options = default_options # .merge(options) - conf = Rack::Handler::Puma.config(app, options) + puma_rack_handler = defined?(Rackup::Handler::Puma) ? Rackup::Handler::Puma : Rack::Handler::Puma + conf = puma_rack_handler.config(app, options) conf.clamp logger = (defined?(::Puma::LogWriter) ? ::Puma::LogWriter : ::Puma::Events).stdio diff --git a/lib/cypress-rails/version.rb b/lib/cypress-rails/version.rb index 59b592b..06e5bc8 100644 --- a/lib/cypress-rails/version.rb +++ b/lib/cypress-rails/version.rb @@ -1,3 +1,3 @@ module CypressRails - VERSION = "0.6.1" + VERSION = "0.7.1" end diff --git a/script/test b/script/test index 290c488..cc27cf4 100755 --- a/script/test +++ b/script/test @@ -15,5 +15,7 @@ echo "---> Running tests" bundle exec rake ./script/test_example_app +bundle exec rake test + echo "---> Job's done!" diff --git a/test/config_test.rb b/test/config_test.rb new file mode 100644 index 0000000..88ddbbd --- /dev/null +++ b/test/config_test.rb @@ -0,0 +1,44 @@ +require_relative "test_helper" + +class ConfigTest < Minitest::Test + def test_that_rails_dir_and_cypress_dir_use_default_directory + config = CypressRails::Config.new + expected_directory_path = Dir.pwd + + assert_equal(expected_directory_path, config.rails_dir) + assert_equal(expected_directory_path, config.cypress_dir) + end + + def test_that_rails_dir_and_cypress_dir_can_be_independently_set + mock_env( + "CYPRESS_RAILS_DIR" => "path/to/cypress-rails", + "CYPRESS_RAILS_CYPRESS_DIR" => "path/to/another/cypress/directory" + ) do + config = CypressRails::Config.new + + assert_equal("path/to/cypress-rails", config.rails_dir) + assert_equal("path/to/another/cypress/directory", config.cypress_dir) + end + end + + def test_that_cypress_dir_uses_same_directory_as_rails_dir_when_not_set + mock_env("CYPRESS_RAILS_DIR" => "path/to/cypress-rails") do + config = CypressRails::Config.new + + assert_nil(ENV["CYPRESS_RAILS_CYPRESS_DIR"]) + assert_equal("path/to/cypress-rails", config.cypress_dir) + end + end + + private + + def mock_env(partial_env_hash) + old = ENV.to_hash + ENV.update partial_env_hash + begin + yield + ensure + ENV.replace old + end + end +end