Sha256: 899c1948a932a30d5baeb3a59462ff9eebaa2109f2fd709022e01e2eacf293e6

Contents?: true

Size: 789 Bytes

Versions: 12

Compression:

Stored size: 789 Bytes

Contents

module CypressRails
  class Init
    DEFAULT_CONFIG = {
      "screenshotsFolder" => "tmp/cypress_screenshots",
      "videosFolder" => "tmp/cypress_videos",
      "trashAssetsBeforeRuns" => false
    }

    def call(dir = Dir.pwd)
      config_path = File.join(dir, "cypress.json")
      json = JSON.pretty_generate(determine_new_config(config_path))
      File.write(config_path, json)
      puts "Cypress config (re)initialized in #{config_path}"
    end

    private

    def determine_new_config(config_path)
      if File.exist?(config_path)
        merge_existing_with_defaults(config_path)
      else
        DEFAULT_CONFIG
      end
    end

    def merge_existing_with_defaults(json_path)
      Hash[JSON.parse(File.read(json_path)).merge(DEFAULT_CONFIG).sort]
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
cypress-rails-0.5.0 lib/cypress-rails/init.rb
cypress-rails-0.4.2 lib/cypress-rails/init.rb
cypress-rails-0.4.1 lib/cypress-rails/init.rb
cypress-rails-0.4.0 lib/cypress-rails/init.rb
cypress-rails-0.3.0 lib/cypress-rails/init.rb
cypress-rails-0.2.0 lib/cypress-rails/init.rb
cypress-rails-0.1.5 lib/cypress-rails/init.rb
cypress-rails-0.1.4 lib/cypress-rails/init.rb
cypress-rails-0.1.3 lib/cypress-rails/init.rb
cypress-rails-0.1.2 lib/cypress-rails/init.rb
cypress-rails-0.1.1 lib/cypress-rails/init.rb
cypress-rails-0.1.0 lib/cypress-rails/init.rb