repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
rack/rack-attack
https://github.com/rack/rack-attack/blob/d1a979dd32ac5783e06d661fab65c8c390019f4b/lib/rack/attack/blocklist.rb
lib/rack/attack/blocklist.rb
# frozen_string_literal: true module Rack class Attack class Blocklist < Check def initialize(name = nil, &block) super @type = :blocklist end end end end
ruby
MIT
d1a979dd32ac5783e06d661fab65c8c390019f4b
2026-01-04T15:42:47.875992Z
false
rack/rack-attack
https://github.com/rack/rack-attack/blob/d1a979dd32ac5783e06d661fab65c8c390019f4b/lib/rack/attack/cache.rb
lib/rack/attack/cache.rb
# frozen_string_literal: true module Rack class Attack class Cache attr_accessor :prefix attr_reader :last_epoch_time def self.default_store if Object.const_defined?(:Rails) && Rails.respond_to?(:cache) ::Rails.cache end end def initialize(store: self.class.default_store) self.store = store @prefix = 'rack::attack' end attr_reader :store def store=(store) @store = if (proxy = BaseProxy.lookup(store)) proxy.new(store) else store end end def count(unprefixed_key, period) key, expires_in = key_and_expiry(unprefixed_key, period) do_count(key, expires_in) end def read(unprefixed_key) enforce_store_presence! enforce_store_method_presence!(:read) store.read("#{prefix}:#{unprefixed_key}") end def write(unprefixed_key, value, expires_in) store.write("#{prefix}:#{unprefixed_key}", value, expires_in: expires_in) end def reset_count(unprefixed_key, period) key, _ = key_and_expiry(unprefixed_key, period) store.delete(key) end def delete(unprefixed_key) store.delete("#{prefix}:#{unprefixed_key}") end def reset! if store.respond_to?(:delete_matched) store.delete_matched(/#{prefix}*/) else raise( Rack::Attack::IncompatibleStoreError, "Configured store #{store.class.name} doesn't respond to #delete_matched method" ) end end private def key_and_expiry(unprefixed_key, period) @last_epoch_time = Time.now.to_i # Add 1 to expires_in to avoid timing error: https://github.com/rack/rack-attack/pull/85 expires_in = (period - (@last_epoch_time % period) + 1).to_i ["#{prefix}:#{(@last_epoch_time / period).to_i}:#{unprefixed_key}", expires_in] end def do_count(key, expires_in) enforce_store_presence! enforce_store_method_presence!(:increment) result = store.increment(key, 1, expires_in: expires_in) # NB: Some stores return nil when incrementing uninitialized values if result.nil? enforce_store_method_presence!(:write) store.write(key, 1, expires_in: expires_in) end result || 1 end def enforce_store_presence! if store.nil? raise Rack::Attack::MissingStoreError end end def enforce_store_method_presence!(method_name) if !store.respond_to?(method_name) raise( Rack::Attack::MisconfiguredStoreError, "Configured store #{store.class.name} doesn't respond to ##{method_name} method" ) end end end end end
ruby
MIT
d1a979dd32ac5783e06d661fab65c8c390019f4b
2026-01-04T15:42:47.875992Z
false
rack/rack-attack
https://github.com/rack/rack-attack/blob/d1a979dd32ac5783e06d661fab65c8c390019f4b/lib/rack/attack/store_proxy/mem_cache_store_proxy.rb
lib/rack/attack/store_proxy/mem_cache_store_proxy.rb
# frozen_string_literal: true require 'rack/attack/base_proxy' module Rack class Attack module StoreProxy class MemCacheStoreProxy < BaseProxy def self.handle?(store) defined?(::Dalli) && defined?(::ActiveSupport::Cache::MemCacheStore) && store.is_a?(::ActiveSupport::Cache::MemCacheStore) end def read(name, options = {}) super(name, options.merge!(raw: true)) end def write(name, value, options = {}) super(name, value, options.merge!(raw: true)) end end end end end
ruby
MIT
d1a979dd32ac5783e06d661fab65c8c390019f4b
2026-01-04T15:42:47.875992Z
false
rack/rack-attack
https://github.com/rack/rack-attack/blob/d1a979dd32ac5783e06d661fab65c8c390019f4b/lib/rack/attack/store_proxy/redis_store_proxy.rb
lib/rack/attack/store_proxy/redis_store_proxy.rb
# frozen_string_literal: true require 'rack/attack/store_proxy/redis_proxy' module Rack class Attack module StoreProxy class RedisStoreProxy < RedisProxy def self.handle?(store) defined?(::Redis::Store) && store.is_a?(::Redis::Store) end def read(key) rescuing { get(key, raw: true) } end def write(key, value, options = {}) if (expires_in = options[:expires_in]) rescuing { setex(key, expires_in, value, raw: true) } else rescuing { set(key, value, raw: true) } end end end end end end
ruby
MIT
d1a979dd32ac5783e06d661fab65c8c390019f4b
2026-01-04T15:42:47.875992Z
false
rack/rack-attack
https://github.com/rack/rack-attack/blob/d1a979dd32ac5783e06d661fab65c8c390019f4b/lib/rack/attack/store_proxy/dalli_proxy.rb
lib/rack/attack/store_proxy/dalli_proxy.rb
# frozen_string_literal: true require 'rack/attack/base_proxy' module Rack class Attack module StoreProxy class DalliProxy < BaseProxy def self.handle?(store) return false unless defined?(::Dalli) # Consider extracting to a separate Connection Pool proxy to reduce # code here and handle clients other than Dalli. if defined?(::ConnectionPool) && store.is_a?(::ConnectionPool) store.with { |conn| conn.is_a?(::Dalli::Client) } else store.is_a?(::Dalli::Client) end end def initialize(client) super(client) stub_with_if_missing end def read(key) rescuing do with do |client| client.get(key) end end end def write(key, value, options = {}) rescuing do with do |client| client.set(key, value, options.fetch(:expires_in, 0), raw: true) end end end def increment(key, amount, options = {}) rescuing do with do |client| client.incr(key, amount, options.fetch(:expires_in, 0), amount) end end end def delete(key) rescuing do with do |client| client.delete(key) end end end private def stub_with_if_missing unless __getobj__.respond_to?(:with) class << self def with yield __getobj__ end end end end def rescuing yield rescue Dalli::DalliError nil end end end end end
ruby
MIT
d1a979dd32ac5783e06d661fab65c8c390019f4b
2026-01-04T15:42:47.875992Z
false
rack/rack-attack
https://github.com/rack/rack-attack/blob/d1a979dd32ac5783e06d661fab65c8c390019f4b/lib/rack/attack/store_proxy/redis_proxy.rb
lib/rack/attack/store_proxy/redis_proxy.rb
# frozen_string_literal: true require 'rack/attack/base_proxy' module Rack class Attack module StoreProxy class RedisProxy < BaseProxy def initialize(*args) if Gem::Version.new(Redis::VERSION) < Gem::Version.new("3") warn 'RackAttack requires Redis gem >= 3.0.0.' end super(*args) end def self.handle?(store) defined?(::Redis) && store.class == ::Redis end def read(key) rescuing { get(key) } end def write(key, value, options = {}) if (expires_in = options[:expires_in]) rescuing { setex(key, expires_in, value) } else rescuing { set(key, value) } end end def increment(key, amount, options = {}) rescuing do pipelined do |redis| redis.incrby(key, amount) redis.expire(key, options[:expires_in]) if options[:expires_in] end.first end end def delete(key, _options = {}) rescuing { del(key) } end def delete_matched(matcher, _options = nil) cursor = "0" source = matcher.source rescuing do # Fetch keys in batches using SCAN to avoid blocking the Redis server. loop do cursor, keys = scan(cursor, match: source, count: 1000) del(*keys) unless keys.empty? break if cursor == "0" end end end private def rescuing yield rescue Redis::BaseConnectionError nil end end end end end
ruby
MIT
d1a979dd32ac5783e06d661fab65c8c390019f4b
2026-01-04T15:42:47.875992Z
false
rack/rack-attack
https://github.com/rack/rack-attack/blob/d1a979dd32ac5783e06d661fab65c8c390019f4b/lib/rack/attack/store_proxy/redis_cache_store_proxy.rb
lib/rack/attack/store_proxy/redis_cache_store_proxy.rb
# frozen_string_literal: true require 'rack/attack/base_proxy' module Rack class Attack module StoreProxy class RedisCacheStoreProxy < BaseProxy def self.handle?(store) store.class.name == "ActiveSupport::Cache::RedisCacheStore" end if defined?(::ActiveSupport) && ::ActiveSupport::VERSION::MAJOR < 6 def increment(name, amount = 1, **options) # RedisCacheStore#increment ignores options[:expires_in] in versions prior to 6. # # So in order to workaround this we use RedisCacheStore#write (which sets expiration) to initialize # the counter. After that we continue using the original RedisCacheStore#increment. if options[:expires_in] && !read(name) write(name, amount, options) amount else super end end end def read(name, options = {}) super(name, options.merge!(raw: true)) end def write(name, value, options = {}) super(name, value, options.merge!(raw: true)) end def delete_matched(matcher, options = nil) super(matcher.source, options) end end end end end
ruby
MIT
d1a979dd32ac5783e06d661fab65c8c390019f4b
2026-01-04T15:42:47.875992Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/danger_plugins/protect_files.rb
danger_plugins/protect_files.rb
# frozen_string_literal: true module Danger class Files < Plugin def protect_files(path: nil, message: nil, fail_build: true) raise "You have to provide a message" if message.to_s.empty? raise "You have to provide a path" if path.to_s.empty? broken_rule = git.modified_files.include?(path) return unless broken_rule fail_build ? fail(message) : warn(message) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/danger_spec.rb
spec/danger_spec.rb
# frozen_string_literal: true require "danger/clients/rubygems_client" RSpec.describe Danger do context "when installed danger is outdated and an error is raised" do before do stub_const("Danger::VERSION", "1.0.0") allow(Danger::RubyGemsClient).to receive(:latest_danger_version) { "2.0.0" } end it "prints an upgrade message" do message = "exception message" path = "path" exception = StandardError.new("error message") contents = "contents" expect do raise Danger::DSLError.new(message, path, exception.backtrace, contents) end.to raise_error( Danger::DSLError, /. Updating the Danger gem might fix the issue. Your Danger version: 1.0.0, latest Danger version: 2.0.0/ ) end end describe ".gem_path" do context "when danger gem found" do it "returns danger gem path" do result = Danger.gem_path expect(result).to match(/danger/i) end end context "when danger gem folder not found" do it "raises an error" do allow(Gem::Specification).to receive(:find_all_by_name) { [] } expect { Danger.gem_path }.to raise_error("Couldn't find gem directory for 'danger'") end end end describe ".danger_outdated?" do it "latest danger > local danger version" do allow(Danger::RubyGemsClient).to receive(:latest_danger_version) { "2.0.0" } stub_const("Danger::VERSION", "1.0.0") result = Danger.danger_outdated? expect(result).to eq "2.0.0" end it "latest danger < local danger version" do allow(Danger::RubyGemsClient).to receive(:latest_danger_version) { "1.0.0" } stub_const("Danger::VERSION", "2.0.0") result = Danger.danger_outdated? expect(result).to be false end end context "when danger-gitlab is not installed" do it "gracefully handles missing gitlab gem without raising LoadError" do # danger is already required in spec_helper.rb so we have to launch a new process. script = <<~RUBY # Emulate the environment that does not have gitlab gem. module Kernel alias original_require require def require(name) raise LoadError, "cannot load such file -- gitlab" if name == "gitlab" original_require(name) end end require "danger" Danger::Runner.run([]) RUBY expect { system(RbConfig.ruby, "-e", script) }.not_to output(/LoadError/).to_stderr_from_any_process end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/spec_helper.rb
spec/spec_helper.rb
# frozen_string_literal: true $LOAD_PATH.unshift File.expand_path("../lib", __dir__) $LOAD_PATH.unshift File.expand_path("..", __dir__) # Needs to be required and started before danger require "simplecov" SimpleCov.start do add_filter "/spec/" end require "danger" require "webmock" require "webmock/rspec" require "json" Dir["spec/support/**/*.rb"].sort.each { |file| require(file) } RSpec.configure do |config| config.filter_gems_from_backtrace "bundler" config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true end config.shared_context_metadata_behavior = :apply_to_host_groups config.filter_run_when_matching :focus config.example_status_persistence_file_path = "spec/examples.txt" if config.files_to_run.one? config.default_formatter = "doc" end config.disable_monkey_patching! config.order = :random Kernel.srand config.seed # Custom config.include Danger::Support::GitLabHelper, host: :gitlab config.include Danger::Support::GitHubHelper, host: :github config.include Danger::Support::BitbucketServerHelper, host: :bitbucket_server config.include Danger::Support::BitbucketCloudHelper, host: :bitbucket_cloud config.include Danger::Support::VSTSHelper, host: :vsts config.include Danger::Support::CIHelper, use: :ci_helper end # Now that we could be using Danger's plugins in Danger Danger::Plugin.clear_external_plugins WebMock.disable_net_connect!(allow: "coveralls.io") def make_temp_file(contents) file = Tempfile.new("dangefile_tests") file.write contents file end def testing_ui @output = StringIO.new @err = StringIO.new def @output.winsize [20, 9999] end cork = Cork::Board.new(out: @output, err: @err) def cork.string out.string.gsub(/\e\[([;\d]+)?m/, "") end def cork.err_string err.string.gsub(/\e\[([;\d]+)?m/, "") end cork end def testing_dangerfile(env = stub_env) env_manager = Danger::EnvironmentManager.new(env, testing_ui) dm = Danger::Dangerfile.new(env_manager, testing_ui) end def fixture_txt(file) File.read("spec/fixtures/#{file}.txt") end def fixture(file) File.read("spec/fixtures/#{file}.json") end def comment_fixture(file) File.read("spec/fixtures/#{file}.html") end def diff_fixture(file) File.read("spec/fixtures/#{file}.diff") end def violation_factory(message, sticky: false, file: nil, line: nil, **hash_args) Danger::Violation.new(message, sticky, file, line, **hash_args) end def violations_factory(messages, sticky: false) messages.map { |s| violation_factory(s, sticky: sticky) } end def markdown_factory(message) Danger::Markdown.new(message) end def markdowns_factory(messages) messages.map { |s| markdown_factory(s) } end def with_git_repo(origin: "git@github.com:artsy/eigen") Dir.mktmpdir do |dir| Dir.chdir dir do `git init -b master` File.open("#{dir}/file1", "w") {} `git add .` `git commit --no-gpg-sign -m "ok"` `git checkout -b new --quiet` File.open("#{dir}/file2", "w") {} `git add .` `git commit --no-gpg-sign -m "another"` `git remote add origin #{origin}` Dir.mkdir("#{dir}/subdir") yield dir end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/support/ci_helper.rb
spec/support/ci_helper.rb
# frozen_string_literal: true # rubocop:disable Metrics/ModuleLength module Danger module Support module CIHelper def github_token { "DANGER_GITHUB_API_TOKEN" => "1234567890" * 4 } end def with_appcircle_setup_and_is_a_pull_request system_env = { "AC_APPCIRCLE" => "true", "AC_PULL_NUMBER" => "42", "AC_GIT_URL" => "git@github.com:danger/danger" } yield(system_env) end def with_bamboo_setup_and_is_a_pull_request system_env = { "bamboo_buildKey" => "1", "bamboo_repository_pr_key" => "33", "bamboo_planRepository_repositoryUrl" => "git@github.com:danger/danger" } yield(system_env) end def with_bitrise_setup_and_is_a_pull_request system_env = { "BITRISE_IO" => "true", "BITRISE_PULL_REQUEST" => "42" } yield(system_env) end def with_buildkite_setup_and_is_a_pull_request system_env = { "BUILDKITE" => "true", "BUILDKITE_PULL_REQUEST_REPO" => "true", "BUILDKITE_PULL_REQUEST" => "42" } yield(system_env) end def with_circle_setup_and_is_a_pull_request system_env = { "CIRCLE_BUILD_NUM" => "1589", "CI_PULL_REQUEST" => "https://circleci.com/gh/danger/danger/1589", "DANGER_CIRCLE_CI_API_TOKEN" => "circle api token", "CIRCLE_PROJECT_USERNAME" => "danger", "CIRCLE_PROJECT_REPONAME" => "danger" } yield(system_env) end def with_codefresh_setup_and_is_a_pull_request system_env = { "CF_BUILD_ID" => "89", "CF_BUILD_URL" => "https://g.codefresh.io//build/qwerty123456", "CF_PULL_REQUEST_NUMBER" => "41", "CF_REPO_OWNER" => "Danger", "CF_REPO_NAME" => "danger", "CF_COMMIT_URL" => "https://github.com/danger/danger/commit/qwerty123456" } yield(system_env) end def with_codemagic_setup_and_is_a_pull_request system_env = { "FCI_PROJECT_ID" => "23", "FCI_PULL_REQUEST_NUMBER" => "42" } yield(system_env) end def with_drone_setup_and_is_a_pull_request system_env = { "DRONE_REPO_NAME" => "danger", "DRONE_REPO_OWNER" => "danger", "DRONE_PULL_REQUEST" => "42" } yield(system_env) end def with_gitlabci_setup_and_is_a_merge_request system_env = { "GITLAB_CI" => "true", "CI_PROJECT_PATH" => "danger/danger", "CI_MERGE_REQUEST_IID" => "42", "CI_MERGE_REQUEST_PROJECT_PATH" => "danger/danger" } yield(system_env) end def with_gitlabci_setup_and_is_not_a_merge_request system_env = { "GITLAB_CI" => "true", "CI_PROJECT_PATH" => "danger/danger" } yield(system_env) end def with_jenkins_setup_github_and_is_a_pull_request system_env = { "JENKINS_URL" => "https://ci.swift.org/job/oss-swift-incremental-RA-osx/lastBuild/", "ghprbPullId" => "42" } yield(system_env) end def with_jenkins_setup_gitlab_and_is_a_merge_request system_env = { "JENKINS_URL" => "https://ci.swift.org/job/oss-swift-incremental-RA-osx/lastBuild/", "gitlabMergeRequestIid" => "42" } yield(system_env) end def with_jenkins_setup_gitlab_v3_and_is_a_merge_request system_env = { "JENKINS_URL" => "https://ci.swift.org/job/oss-swift-incremental-RA-osx/lastBuild/", "gitlabMergeRequestId" => "42" } yield(system_env) end def with_localgitrepo_setup system_env = { "DANGER_USE_LOCAL_GIT" => "true" } yield(system_env) end def with_localonlygitrepo_setup system_env = { "DANGER_USE_LOCAL_ONLY_GIT" => "true" } yield(system_env) end def with_screwdriver_setup_and_is_a_pull_request system_env = { "SCREWDRIVER" => "true", "SD_PULL_REQUEST" => "42", "SCM_URL" => "git@github.com:danger/danger" } yield(system_env) end def with_semaphore_setup_and_is_a_pull_request system_env = { "SEMAPHORE" => "true", "SEMAPHORE_GIT_PR_NUMBER" => "800", "SEMAPHORE_GIT_REPO_SLUG" => "artsy/eigen", "SEMAPHORE_GIT_URL" => "git@github.com:artsy/eigen" } yield(system_env) end def with_surf_setup_and_is_a_pull_request system_env = { "SURF_REPO" => "true", "SURF_NWO" => "danger/danger" } yield(system_env) end def with_teamcity_setup_github_and_is_a_pull_request system_env = { "TEAMCITY_VERSION" => "1.0.0", "GITHUB_PULL_REQUEST_ID" => "42", "GITHUB_REPO_URL" => "https://github.com/danger/danger" } yield(system_env) end def with_teamcity_setup_gitlab_and_is_a_merge_request system_env = { "TEAMCITY_VERSION" => "1.0.0", "GITLAB_REPO_SLUG" => "danger/danger", "GITLAB_PULL_REQUEST_ID" => "42", "GITLAB_REPO_URL" => "gitlab.com/danger/danger" } yield(system_env) end def with_travis_setup_and_is_a_pull_request(request_source: nil) system_env = { "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true", "TRAVIS_PULL_REQUEST" => "42", "TRAVIS_REPO_SLUG" => "orta/orta" } if request_source == :github system_env.merge!(github_token) end yield(system_env) end def with_xcodeserver_setup_and_is_a_pull_request system_env = { "XCS_BOT_NAME" => "Danger BuildaBot" } yield(system_env) end def we_dont_have_ci_setup yield({}) end def not_a_pull_request system_env = { "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true", "TRAVIS_REPO_SLUG" => "orta/orta" } yield(system_env) end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/support/github_helper.rb
spec/support/github_helper.rb
# frozen_string_literal: true module Danger module Support module GitHubHelper def expected_headers {} end def stub_env { "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true", "TRAVIS_PULL_REQUEST" => "800", "TRAVIS_REPO_SLUG" => "artsy/eigen", "TRAVIS_COMMIT_RANGE" => "759adcbd0d8f...13c4dc8bb61d", "DANGER_GITHUB_API_TOKEN" => "hi" } end def stub_ci env = { "CI_PULL_REQUEST" => "https://github.com/artsy/eigen/pull/800" } Danger::CircleCI.new(env) end def stub_request_source Danger::RequestSources::GitHub.new(stub_ci, stub_env) end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/support/vsts_helper.rb
spec/support/vsts_helper.rb
# frozen_string_literal: true module Danger module Support module VSTSHelper def stub_env { "AGENT_ID" => "4a4d3fa1-bae7-4e5f-a14a-a50b184c74aa", "DANGER_VSTS_HOST" => "https://example.visualstudio.com/example", "DANGER_VSTS_API_TOKEN" => "a_token", "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI" => "https://example.visualstudio.com", "BUILD_SOURCEBRANCH" => "refs/pull/1/merge", "BUILD_REPOSITORY_URI" => "https://example.visualstudio.com/_git/example", "BUILD_REASON" => "PullRequest", "BUILD_REPOSITORY_NAME" => "example", "SYSTEM_TEAMPROJECT" => "example", "SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" => 1, "BUILD_REPOSITORY_PROVIDER" => "TfsGit" } end def stub_ci Danger::AzurePipelines.new(stub_env) end def stub_request_source Danger::RequestSources::VSTS.new(stub_ci, stub_env) end def stub_pull_request raw_file = File.new("spec/fixtures/vsts_api/pr_response.json") url = "https://example.visualstudio.com/example/_apis/git/repositories/example/pullRequests/1?api-version=3.0" WebMock.stub_request(:get, url).to_return(raw_file) end def stub_get_comments_request_no_danger raw_file = File.new("spec/fixtures/vsts_api/no_danger_comments_response.json") url = "https://example.visualstudio.com/example/_apis/git/repositories/example/pullRequests/1/threads?api-version=3.0" WebMock.stub_request(:get, url).to_return(raw_file) end def stub_get_comments_request_with_danger raw_file = File.new("spec/fixtures/vsts_api/danger_comments_response.json") url = "https://example.visualstudio.com/example/_apis/git/repositories/example/pullRequests/1/threads?api-version=3.0" WebMock.stub_request(:get, url).to_return(raw_file) end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/support/gitlab_helper.rb
spec/support/gitlab_helper.rb
# frozen_string_literal: true module Danger module Support module GitLabHelper def expected_headers { "Accept" => "application/json", "PRIVATE-TOKEN" => stub_env["DANGER_GITLAB_API_TOKEN"] } end def stub_env { "GITLAB_CI" => "1", "CI_COMMIT_SHA" => "3333333333333333333333333333333333333333", "CI_PROJECT_PATH" => "k0nserv/danger-test", "CI_PROJECT_URL" => "https://gitlab.com/k0nserv/danger-test", "CI_MERGE_REQUEST_PROJECT_PATH" => "k0nserv/danger-test", "CI_MERGE_REQUEST_PROJECT_URL" => "https://gitlab.com/k0nserv/danger-test", "DANGER_GITLAB_API_TOKEN" => "a86e56d46ac78b" } end def stub_env_pre_11_6 { "GITLAB_CI" => "1", "CI_COMMIT_SHA" => "3333333333333333333333333333333333333333", "CI_PROJECT_PATH" => "k0nserv/danger-test", "CI_PROJECT_URL" => "https://gitlab.com/k0nserv/danger-test", "DANGER_GITLAB_API_TOKEN" => "a86e56d46ac78b" } end def stub_ci(env = stub_env) Danger::GitLabCI.new(env) end def stub_request_source(env = stub_env) Danger::RequestSources::GitLab.new(stub_ci(env), env) end def stub_merge_requests(fixture, slug) raw_file = File.new("spec/fixtures/gitlab_api/#{fixture}.json") url = "https://gitlab.com/api/v4/projects/#{slug}/merge_requests?state=opened" WebMock.stub_request(:get, url).with(headers: expected_headers).to_return(raw_file) end def stub_merge_request(fixture, slug, merge_request_id) raw_file = File.new("spec/fixtures/gitlab_api/#{fixture}.json") url = "https://gitlab.com/api/v4/projects/#{slug}/merge_requests/#{merge_request_id}" WebMock.stub_request(:get, url).with(headers: expected_headers).to_return(raw_file) end def stub_merge_request_changes(fixture, slug, merge_request_id) raw_file = File.new("spec/fixtures/gitlab_api/#{fixture}.json") url = "https://gitlab.com/api/v4/projects/#{slug}/merge_requests/#{merge_request_id}/changes" WebMock.stub_request(:get, url).with(headers: expected_headers).to_return(raw_file) end def stub_merge_request_commits(fixture, slug, merge_request_id) raw_file = File.new("spec/fixtures/gitlab_api/#{fixture}.json") url = "https://gitlab.com/api/v4/projects/#{slug}/merge_requests/#{merge_request_id}/commits" WebMock.stub_request(:get, url).with(headers: expected_headers).to_return(raw_file) end def stub_merge_request_comments(fixture, slug, merge_request_id) raw_file = File.new("spec/fixtures/gitlab_api/#{fixture}.json") url = "https://gitlab.com/api/v4/projects/#{slug}/merge_requests/#{merge_request_id}/notes?per_page=100" WebMock.stub_request(:get, url).with(headers: expected_headers).to_return(raw_file) end def stub_merge_request_discussions(fixture, slug, merge_request_id) raw_file = File.new("spec/fixtures/gitlab_api/#{fixture}.json") url = "https://gitlab.com/api/v4/projects/#{slug}/merge_requests/#{merge_request_id}/discussions" WebMock.stub_request(:get, url).with(headers: expected_headers).to_return(raw_file) end def stub_commit_merge_requests(fixture, slug, commit_sha) raw_file = File.new("spec/fixtures/gitlab_api/#{fixture}.json") url = "https://gitlab.com/api/v4/projects/#{slug}/repository/commits/#{commit_sha}/merge_requests?state=opened" WebMock.stub_request(:get, url).with(headers: expected_headers).to_return(raw_file) end def stub_version(version) url = "https://gitlab.com/api/v4/version" WebMock.stub_request(:get, url).with(headers: expected_headers).to_return( body: "{\"version\":\"#{version}\",\"revision\":\"1d9280e\"}" ) end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/support/bitbucket_server_helper.rb
spec/support/bitbucket_server_helper.rb
# frozen_string_literal: true module Danger module Support module BitbucketServerHelper def stub_env { "DANGER_BITBUCKETSERVER_HOST" => "stash.example.com", "DANGER_BITBUCKETSERVER_USERNAME" => "a.name", "DANGER_BITBUCKETSERVER_PASSWORD" => "a_password", "JENKINS_URL" => "http://jenkins.example.com/job/ios-check-pullrequest/", "GIT_URL" => "ssh://git@stash.example.com:7999/ios/fancyapp.git", "ghprbPullId" => "2080" } end def stub_ci Danger::Jenkins.new(stub_env) end def stub_request_source Danger::RequestSources::GitLab.new(stub_ci, stub_env) end def stub_pull_request raw_file = File.new("spec/fixtures/bitbucket_server_api/pr_response.json") url = "https://stash.example.com/rest/api/1.0/projects/ios/repos/fancyapp/pull-requests/2080" WebMock.stub_request(:get, url).to_return(raw_file) end def stub_pull_request_diff raw_file = File.new("spec/fixtures/bitbucket_server_api/pr_diff_response.json") url = "https://stash.example.com/rest/api/1.0/projects/ios/repos/fancyapp/pull-requests/2080/diff?withComments=false" WebMock.stub_request(:get, url).to_return(raw_file) end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/support/bitbucket_cloud_helper.rb
spec/support/bitbucket_cloud_helper.rb
# frozen_string_literal: true module Danger module Support module BitbucketCloudHelper def stub_env { "DANGER_BITBUCKETCLOUD_USERNAME" => "a.name", "DANGER_BITBUCKETCLOUD_UUID" => "c91be865-efc6-49a6-93c5-24e1267c479b", "DANGER_BITBUCKETCLOUD_PASSWORD" => "a_password", "JENKINS_URL" => "http://jenkins.example.com/job/ios-check-pullrequest/", "GIT_URL" => "ssh://git@stash.example.com:7999/ios/fancyapp.git", "ghprbPullId" => "2080" } end def stub_ci Danger::Jenkins.new(stub_env) end def stub_request_source(env = stub_env) Danger::RequestSources::BitbucketCloud.new(stub_ci, env) end def stub_pull_request raw_file = File.new("spec/fixtures/bitbucket_cloud_api/pr_response.json") url = "https://api.bitbucket.org/2.0/repositories/ios/fancyapp/pullrequests/2080" WebMock.stub_request(:get, url).to_return(raw_file) end def stub_pull_requests raw_file = File.new("spec/fixtures/bitbucket_cloud_api/prs_response.json") url = "https://api.bitbucket.org/2.0/repositories/ios/fancyapp/pullrequests?q=source.branch.name=%22feature_branch%22" WebMock.stub_request(:get, url).to_return(raw_file) end def stub_access_token raw_file = File.new("spec/fixtures/bitbucket_cloud_api/oauth2_response.json") url = "https://bitbucket.org/site/oauth2/access_token" WebMock.stub_request(:post, url).to_return(raw_file) end def stub_pull_request_comment raw_file = File.new("spec/fixtures/bitbucket_cloud_api/pr_comments.json") url = "https://api.bitbucket.org/2.0/repositories/ios/fancyapp/pullrequests/2080/comments?pagelen=100&q=deleted+%7E+false+AND+user.uuid+%7E+%22c91be865-efc6-49a6-93c5-24e1267c479b%22" WebMock.stub_request(:get, url).to_return(raw_file) end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/support/matchers/have_instance_variables_matcher.rb
spec/support/matchers/have_instance_variables_matcher.rb
# frozen_string_literal: true RSpec::Matchers.define(:have_instance_variables) do |expected| match do |actual| expected.each do |instance_variable, expected_value| expect(actual.instance_variable_get(instance_variable)).to eq(expected_value) end end failure_message do |actual| expected.each do |instance_variable, expected_value| actual_value = actual.instance_variable_get(instance_variable) if actual_value != expected_value return "expected #{actual}#{instance_variable} to match #{expected_value.inspect}, but got #{actual_value.inspect}." end end end failure_message_when_negated do |actual| expected.each do |instance_variable, expected_value| actual_value = actual.instance_variable_get(instance_variable) if actual_value == expected_value return "expected #{actual}#{instance_variable} not to match #{expected_value.inspect}, but got #{actual_value.inspect}." end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/fixtures/plugins/example_broken.rb
spec/fixtures/plugins/example_broken.rb
module Danger class Dangerfile class ExampleBroken # not a subclass < Plugin def run return "Hi there" end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/fixtures/plugins/example_echo_plugin.rb
spec/fixtures/plugins/example_echo_plugin.rb
module Danger class ExamplePing < Plugin def echo return "Hi there 🎉" end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/fixtures/plugins/example_fully_documented.rb
spec/fixtures/plugins/example_fully_documented.rb
module Danger # Lint markdown files inside your projects. # This is done using the [proselint](http://proselint.com) python egg. # Results are passed out as a table in markdown. # # @example Specifying custom CocoaPods installation options # # # Runs a linter with comma style disabled # proselint.disable_linters = ["misc.scare_quotes", "misc.tense_present"] # proselint.lint_files "_posts/*.md" # # # Runs a linter with all styles, on modified and added markpown files in this PR # proselint.lint_files # # @see artsy/artsy.github.io # @tags blogging, blog, writing, jekyll, middleman, hugo, metalsmith, gatsby, express # class DangerProselint < Plugin # Allows you to disable a collection of linters from being ran. # You can get a list of [them here](https://github.com/amperser/proselint#checks) attr_writer :disable_linters # Lints the globbed files, which can fail your build if # # @param [String] files # A globbed string which should return the files that you want to lint, defaults to nil. # if nil, modified and added files will be used. # @return [void] # def lint_files(files = nil) # Installs a prose checker if needed system "pip install --user proselint" unless proselint_installed? # Check that this is in the user's PATH if `which proselint`.strip.empty? fail "proselint is not in the user's PATH, or it failed to install" end # Either use files provided, or use the modified + added markdown_files = files ? Dir.glob(files) : (modified_files + added_files) markdown_files.select! { |line| line.end_with?(".markdown", ".md") } # TODO: create the disabled linters JSON in ~/.proselintrc # using @disable_linter # Convert paths to proselint results require 'json' result_jsons = Hash[markdown_files.uniq.collect { |v| [v, JSON.parse(`proselint #{v} --json`.strip)] }] proses = result_jsons.select { |path, prose| prose['data']['errors'].count } # Get some metadata about the local setup current_branch = env.request_source.pr_json["head"]["ref"] current_slug = env.ci_source.repo_slug # We got some error reports back from proselint if proses.count > 0 message = "### Proselint found issues\n\n" proses.each do |path, prose| github_loc = "/#{current_slug}/tree/#{current_branch}/#{path}" message << "#### [#{path}](#{github_loc})\n\n" message << "Line | Message | Severity |\n" message << "| --- | ----- | ----- |\n" prose["data"]["errors"].each do |error| message << "#{error['line']} | #{error['message']} | #{error['severity']}\n" end end markdown message end end # Determine if proselint is currently installed in the system paths. # @return [Bool] # def proselint_installed? `which proselint`.strip.empty? end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/fixtures/plugins/example_globbing.rb
spec/fixtures/plugins/example_globbing.rb
module Danger class Dangerfile module DSL class ExampleGlobbing < Plugin def echo return "Hi there globbing" end end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/fixtures/plugins/plugin_many_methods.rb
spec/fixtures/plugins/plugin_many_methods.rb
module Danger class ExampleManyMethodsPlugin < Plugin def one end # Thing two # def two(param1) end def two_point_five(param1 = nil) end # Thing three # # @param [String] param1 # A thing thing, defaults to nil. # @return [void] # def three(param1 = nil) end # Thing four # # @param [Number] param1 # A thing thing, defaults to nil. # @param [String] param2 # Another param # @return [String] # def four(param1 = nil, param2) end # Thing five # # @param [Array<String>] param1 # A thing thing. # @param [Filepath] param2 # Another param # @return [String] # def five(param1 = [], param2, param3) end # Does six # @return [Bool] # def six? end # Attribute docs # # @return [Array<String>] attr_accessor :seven attr_accessor :eight end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/fixtures/plugins/example_remote.rb
spec/fixtures/plugins/example_remote.rb
module Danger class ExampleRemote < Plugin def echo return "Hi there remote 🎉" end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/fixtures/plugins/example_not_broken.rb
spec/fixtures/plugins/example_not_broken.rb
class Dangerfile class ExampleBroken < Danger::Plugin def run return "Hi there" end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/fixtures/plugins/example_exact_path.rb
spec/fixtures/plugins/example_exact_path.rb
module Danger class Dangerfile module DSL class ExampleExactPath < Plugin def echo return "Hi there exact" end end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/danger/helpers/comment_spec.rb
spec/danger/helpers/comment_spec.rb
# frozen_string_literal: true require "danger/helpers/comment" RSpec.describe Danger::Comment do describe ".from_github" do it "initializes with GitHub comment data structure" do github_comment = { "id" => 42, "body" => "github comment" } result = described_class.from_github(github_comment) expect(result).to have_attributes(id: 42, body: "github comment") end end describe ".from_gitlab" do it "initializes with Gitlab comment data structure" do GitlabComment = Struct.new(:id, :body) gitlab_comment = GitlabComment.new(42, "gitlab comment") result = described_class.from_gitlab(gitlab_comment) expect(result).to have_attributes(id: 42, body: "gitlab comment") end end describe "#generated_by_danger?" do it "returns true when body contains generated_by_{identifier}" do comment = described_class.new(42, '"generated_by_orta"') expect(comment.generated_by_danger?("orta")).to be true end it "returns false when body NOT contains generated_by_{identifier}" do comment = described_class.new(42, '"generated_by_orta"') expect(comment.generated_by_danger?("artsy")).to be false end it "returns false when identifier is a substring of actual identifier" do comment = described_class.new(42, '"generated_by_danger2"') expect(comment.generated_by_danger?("danger")).to be false end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/scm_source/git_repo_spec.rb
spec/lib/danger/scm_source/git_repo_spec.rb
# frozen_string_literal: true require "danger/scm_source/git_repo" RSpec.describe Danger::GitRepo, host: :github do describe "#exec" do it "run command with our env set" do git_repo = described_class.new allow(git_repo).to receive(:default_env) { Hash("GIT_EXEC_PATH" => "git-command-path") } result = git_repo.exec("--exec-path") expect(result).to match(/git-command-path/) end end describe "#diff_for_folder" do it "fetches if cannot find commits, raises if still can't find after fetched" do with_git_repo do |dir| @dm = testing_dangerfile allow(@dm.env.scm).to receive(:exec).and_return("") # This is the thing we care about allow(@dm.env.scm).to receive(:exec).with("fetch") expect do @dm.env.scm.diff_for_folder(dir, from: "master", to: "new") end.to raise_error(RuntimeError, /doesn't exist/) end end it "passes commits count in branch to git log" do with_git_repo do |dir| @dm = testing_dangerfile expect_any_instance_of(Git::Base).to( receive(:log).with(1).and_call_original ) @dm.env.scm.diff_for_folder(dir) end end it "assumes the requested folder is the top level git folder by default" do with_git_repo do |dir| @dm = testing_dangerfile expect do @dm.env.scm.diff_for_folder("#{dir}/subdir") end.to raise_error(ArgumentError, /is not the top level git directory/) end end it "looks up the top level git folder when requested" do with_git_repo do |dir| @dm = testing_dangerfile expect do @dm.env.scm.diff_for_folder("#{dir}/subdir", lookup_top_level: true) end.not_to raise_error end end end describe "Return Types" do it "#modified_files returns a FileList object" do with_git_repo do |dir| @dm = testing_dangerfile @dm.env.scm.diff_for_folder(dir, from: "master", to: "new") expect(@dm.git.modified_files.class).to eq(Danger::FileList) end end it "#added_files returns a FileList object" do with_git_repo do |dir| @dm = testing_dangerfile @dm.env.scm.diff_for_folder(dir, from: "master", to: "new") expect(@dm.git.added_files.class).to eq(Danger::FileList) end end it "#deleted_files returns a FileList object" do with_git_repo do |dir| @dm = testing_dangerfile @dm.env.scm.diff_for_folder(dir, from: "master", to: "new") expect(@dm.git.deleted_files.class).to eq(Danger::FileList) end end end describe "with files" do it "handles adding a new file to a git repo" do with_git_repo do |dir| @dm = testing_dangerfile @dm.env.scm.diff_for_folder(dir, from: "master", to: "new") expect(@dm.git.added_files).to eq(Danger::FileList.new(["file2"])) expect(@dm.git.diff_for_file("file2")).not_to be_nil end end it "handles file deletions as expected" do Dir.mktmpdir do |dir| Dir.chdir dir do `git init -b master` `git remote add origin git@github.com:danger/danger.git` File.open("#{dir}/file", "w") { |file| file.write("hi\n\nfb\nasdasd") } `git add .` `git commit --no-gpg-sign -m "ok"` `git checkout -b new --quiet` File.delete("#{dir}/file") `git add . --all` `git commit --no-gpg-sign -m "another"` @dm = testing_dangerfile @dm.env.scm.diff_for_folder(dir, from: "master", to: "new") expect(@dm.git.deleted_files).to eq(Danger::FileList.new(["file"])) end end end it "handles modified as expected" do Dir.mktmpdir do |dir| Dir.chdir dir do `git init -b master` `git remote add origin git@github.com:danger/danger.git` File.open("#{dir}/file", "w") { |file| file.write("hi\n\nfb\nasdasd") } `git add .` `git commit --no-gpg-sign -m "ok"` `git checkout -b new --quiet` File.open("#{dir}/file", "a") { |file| file.write("ok\nmorestuff") } `git add .` `git commit --no-gpg-sign -m "another"` @dm = testing_dangerfile @dm.env.scm.diff_for_folder(dir, from: "master", to: "new") # Need to compact here because c50713a changes make AppVeyor fail expect(@dm.git.modified_files.compact).to eq(Danger::FileList.new(["file"])) end end end it "handles moved files as expected" do Dir.mktmpdir do |dir| Dir.chdir dir do subfolder = "subfolder" `git init -b master` `git config diff.renames true` `git remote add origin git@github.com:danger/danger.git` File.open("#{dir}/file", "w") { |file| file.write("hi\n\nfb\nasdasd") } `git add .` `git commit --no-gpg-sign -m "ok"` `git checkout -b new --quiet` `mkdir "#{subfolder}"` `git mv file "#{subfolder}"` `git commit --no-gpg-sign -m "another"` @dm = testing_dangerfile @dm.env.scm.diff_for_folder(dir, from: "master", to: "new") # Need to compact here because c50713a changes make AppVeyor fail expect(@dm.git.modified_files.compact).to eq(Danger::FileList.new(["file"])) expect(@dm.git.diff_for_file("file")).not_to be_nil end end end end describe "lines of code" do it "handles code insertions as expected" do Dir.mktmpdir do |dir| Dir.chdir dir do `git init -b master` `git remote add origin git@github.com:danger/danger.git` File.open("#{dir}/file", "w") { |file| file.write("hi\n\nfb\nasdasd") } `git add .` `git commit --no-gpg-sign -m "ok"` `git checkout -b new --quiet` File.open("#{dir}/file", "a") { |file| file.write("hi\n\najsdha") } `git add .` `git commit --no-gpg-sign -m "another"` @dm = testing_dangerfile @dm.env.scm.diff_for_folder(dir, from: "master", to: "new") expect(@dm.git.insertions).to eq(3) end end end it "handles code deletions as expected" do Dir.mktmpdir do |dir| Dir.chdir dir do `git init -b master` `git remote add origin git@github.com:danger/danger.git` File.open("#{dir}/file", "w") { |file| file.write("1\n2\n3\n4\n5\n") } `git add .` `git commit --no-gpg-sign -m "ok"` `git checkout -b new --quiet` File.open("#{dir}/file", "w") { |file| file.write("1\n2\n3\n5\n") } `git add .` `git commit --no-gpg-sign -m "another"` @dm = testing_dangerfile @dm.env.scm.diff_for_folder(dir, from: "master", to: "new") expect(@dm.git.deletions).to eq(1) end end end describe "#commits" do it "returns the commits" do with_git_repo do |dir| @dm = testing_dangerfile @dm.env.scm.diff_for_folder(dir, from: "master", to: "new") messages = @dm.git.commits.map(&:message) expect(messages).to eq(["another"]) end end end end describe "#renamed_files" do it "returns array of hashes with names before and after" do Dir.mktmpdir do |dir| Dir.chdir dir do `git init -b master` `git remote add origin git@github.com:danger/danger.git` Dir.mkdir(File.join(dir, "first")) Dir.mkdir(File.join(dir, "second")) File.open(File.join(dir, "first", "a"), "w") { |f| f.write("hi") } File.open(File.join(dir, "second", "b"), "w") { |f| f.write("bye") } File.open(File.join(dir, "c"), "w") { |f| f.write("Hello") } `git add .` `git commit --no-gpg-sign -m "Add files"` `git checkout -b rename_files --quiet` File.delete(File.join(dir, "first", "a")) File.delete(File.join(dir, "second", "b")) File.delete(File.join(dir, "c")) File.open(File.join(dir, "a"), "w") { |f| f.write("hi") } File.open(File.join(dir, "first", "b"), "w") { |f| f.write("bye") } File.open(File.join(dir, "second", "c"), "w") { |f| f.write("Hello") } # Use -A here cause for older versions of git # add . don't add removed files to index `git add -A .` `git commit --no-gpg-sign -m "Rename files"` @dm = testing_dangerfile @dm.env.scm.diff_for_folder(dir, from: "master", to: "rename_files") expectation = [ { before: "first/a", after: "a" }, { before: "second/b", after: "first/b" }, { before: "c", after: "second/c" } ] expect(@dm.git.renamed_files).to eq(expectation) end end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/helpers/emoji_mapper_spec.rb
spec/lib/danger/helpers/emoji_mapper_spec.rb
# frozen_string_literal: true RSpec.describe Danger::EmojiMapper do subject(:emoji_mapper) { described_class.new(template) } shared_examples_for "github" do describe "#map" do subject { emoji_mapper.map(emoji) } context "when emoji is no_entry_sign" do let(:emoji) { "no_entry_sign" } it { is_expected.to eq "🚫" } end context "when emoji is warning" do let(:emoji) { "warning" } it { is_expected.to eq "⚠️" } end context "when emoji is book" do let(:emoji) { "book" } it { is_expected.to eq "📖" } end context "when emoji is white_check_mark" do let(:emoji) { "white_check_mark" } it { is_expected.to eq "✅" } end end describe "#from_type" do subject { emoji_mapper.from_type(type) } context "when type is :error" do let(:type) { :error } it { is_expected.to eq "🚫" } end context "when type is warning" do let(:type) { :warning } it { is_expected.to eq "⚠️" } end context "when type is message" do let(:type) { :message } it { is_expected.to eq "📖" } end end end context "when template is github" do let(:template) { "github" } include_examples "github" end context "when template is something weird" do let(:template) { "respect_potatoes" } it_behaves_like "github" end context "when template is bitbucket_server" do let(:template) { "bitbucket_server" } describe "#map" do subject { emoji_mapper.map(emoji) } context "when emoji is no_entry_sign" do let(:emoji) { "no_entry_sign" } it { is_expected.to eq ":no_entry_sign:" } end context "when emoji is warning" do let(:emoji) { "warning" } it { is_expected.to eq ":warning:" } end context "when emoji is book" do let(:emoji) { "book" } it { is_expected.to eq ":blue_book:" } end context "when emoji is white_check_mark" do let(:emoji) { "white_check_mark" } it { is_expected.to eq ":white_check_mark:" } end end describe "#from_type" do subject { emoji_mapper.from_type(type) } context "when type is :error" do let(:type) { :error } it { is_expected.to eq ":no_entry_sign:" } end context "when type is warning" do let(:type) { :warning } it { is_expected.to eq ":warning:" } end context "when type is message" do let(:type) { :message } it { is_expected.to eq ":blue_book:" } end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/helpers/message_groups_array_helper_spec.rb
spec/lib/danger/helpers/message_groups_array_helper_spec.rb
# frozen_string_literal: true require "danger/danger_core/message_group" require "danger/helpers/message_groups_array_helper" RSpec.describe Danger::Helpers::MessageGroupsArrayHelper do subject(:array) do class << message_groups include Danger::Helpers::MessageGroupsArrayHelper end message_groups end let(:message_groups) { [] } it { is_expected.to be_a Array } it { is_expected.to respond_to :fake_warnings_array } it { is_expected.to respond_to :fake_errors_array } shared_context "with two message groups" do let(:message_group_a) { double(Danger::MessageGroup.new) } let(:message_group_b) { double(Danger::MessageGroup.new) } let(:message_groups) { [message_group_a, message_group_b] } end describe "#fake_warnings_array" do subject { array.fake_warnings_array } context "with no message groups" do it "returns an fake array with a count method which returns 0" do expect(subject.count).to eq 0 end end context "with two message groups" do include_context "with two message groups" before do allow(message_group_a).to receive(:stats).and_return(warnings_count: 10, errors_count: 35) allow(message_group_b).to receive(:stats).and_return(warnings_count: 6, errors_count: 9) end it "returns an fake array with a count method which returns 0" do expect(subject.count).to eq 16 end end end describe "#fake_errors_array" do subject { array.fake_errors_array } context "with no message groups" do it "returns an fake array with a count method which returns 0" do expect(subject.count).to eq 0 end end context "with two message groups" do include_context "with two message groups" before do allow(message_group_a).to receive(:stats).and_return(warnings_count: 10, errors_count: 35) allow(message_group_b).to receive(:stats).and_return(warnings_count: 6, errors_count: 9) end it "returns an fake array with a count method which returns 44" do expect(subject.count).to eq 44 end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/helpers/array_subclass_spec.rb
spec/lib/danger/helpers/array_subclass_spec.rb
# frozen_string_literal: true RSpec.describe Danger::Helpers::ArraySubclass do class List; include Danger::Helpers::ArraySubclass; end class OtherList; include Danger::Helpers::ArraySubclass; end it "acts as array" do first_list = List.new([1, 2, 3]) second_list = List.new([4, 5, 6]) third_list = List.new([1, 2, 3]) fourth_list = List.new([7, 7]) mapped_list = first_list.map { |item| item + 1 } concated_list = first_list + second_list mapped_mutated_list = third_list.map! { |item| item + 10 } deleted_from_list = fourth_list.delete_at(0) reduced_list = first_list.each_with_object({}) do |el, accum| accum.store(el, el) end expect(first_list.length).to eq(3) expect(mapped_list).to eq(List.new([2, 3, 4])) expect(concated_list).to eq(List.new([1, 2, 3, 4, 5, 6])) expect(third_list).to eq(List.new([11, 12, 13])) expect(mapped_mutated_list).to eq(List.new([11, 12, 13])) expect(deleted_from_list).to eq(7) expect(fourth_list).to eq(List.new([7])) expect(reduced_list).to eq({ 1 => 1, 2 => 2, 3 => 3 }) end describe "equality" do it "equals with same class same size and same values" do first_list = List.new([1, 2, 3]) second_list = List.new([1, 2, 3]) third_list = List.new([4, 5, 6]) expect(first_list).to eq(second_list) expect(first_list).not_to eq(third_list) end it "not equals with other classes" do first_list = List.new([1, 2, 3]) second_list = OtherList.new([1, 2, 3]) third_list = [4, 5, 6] expect(first_list).not_to eq(second_list) expect(first_list).not_to eq(third_list) end end describe "#respond_to_missing?" do context "with missing method" do it "returns false" do list = List.new([]) expect(list.respond_to?(:missing_method)).to be(false) end end context "with existing method" do it "returns true" do list = List.new([]) expect(list.respond_to?(:to_a)).to be(true) end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/helpers/comments_helper_spec.rb
spec/lib/danger/helpers/comments_helper_spec.rb
# frozen_string_literal: true require "danger/helpers/comments_helper" require "danger/danger_core/messages/violation" require "danger/danger_core/messages/markdown" require "danger/danger_core/message_group" SINGLE_TABLE_COMMENT = <<-EOS Other comment content <table> <thead><tr><th width="50"></th><th width="100%">1 Error</th></tr></thead> <tbody><tr> <td> <g-emoji alias="no_entry_sign" fallback-src="https://example.com/1f6ab.png">🚫</g-emoji </td> <td data-sticky="true"><p>Please include a CHANGELOG entry. You can find it at <a href="https://github.com/danger/danger/blob/master/CHANGELOG.md">CHANGELOG.md</a>.</p> </td></tr></tbody> </table> <p align="right" data-meta="generated_by_danger"> Generated by :no_entry_sign: <a href="https://danger.systems/">Danger</a> </p> EOS MULTI_TABLE_COMMENT = <<-EOS Other comment content <table> <thead><tr><th width="50"></th><th width="100%">1 Error</th></tr></thead> <tbody><tr> <td> <g-emoji alias="no_entry_sign" fallback-src="https://example.com/1f6ab.png">🚫</g-emoji </td> <td data-sticky="true"><p>Please include a CHANGELOG entry. You can find it at <a href="https://github.com/danger/danger/blob/master/CHANGELOG.md">CHANGELOG.md</a>.</p> </td></tr></tbody> </table> <table> <thead><tr><th width="50"></th><th width="100%">1 Warning</th></tr></thead> <tbody><tr> <td> <g-emoji alias="warning" fallback-src="https://example.com/unicode/26a0.png">⚠️</g-emoji> </td> <td data-sticky="true"><p>External contributor has edited the Gemspec</p> </td></tr></tbody> </table> <p align="right" data-meta="generated_by_danger"> Generated by :no_entry_sign: <a href="https://danger.systems/">Danger</a> </p> EOS GITHUB_MAX_COMMENT_LENGTH = 65_536 SINGLE_TABLE_COMMENT_NEW_TABLE_IDENTIFIER = <<-EOS Other comment content <table> <thead><tr><th width="50"></th><th data-danger-table="true" width="95%">1 Error</th></tr></thead> <tbody><tr> <td> <g-emoji alias="no_entry_sign" fallback-src="https://example.com/1f6ab.png">🚫</g-emoji </td> <td data-sticky="true"><p>Please include a CHANGELOG entry. You can find it at <a href="https://github.com/danger/danger/blob/master/CHANGELOG.md">CHANGELOG.md</a>.</p> </td></tr></tbody> </table> <p align="right" data-meta="generated_by_danger"> Generated by :no_entry_sign: <a href="https://danger.systems/">Danger</a> </p> EOS class Dummy end RSpec.describe Danger::Helpers::CommentsHelper do let(:dummy) do Dummy.new.tap { |dummy| dummy.extend(described_class) } end describe "#markdown_parser" do it "is a Kramdown::Document instance" do parser = dummy.markdown_parser("") expect(parser).to be_an_instance_of(Kramdown::Document) end end describe "#parse_tables_from_comment" do it "splits a single table comment" do result = dummy.parse_tables_from_comment(SINGLE_TABLE_COMMENT) expect(result.size).to be(2) expect(result[0]).to include("<table>") expect(result[0]).to include("<thead>") expect(result[0]).to include("<tbody>") expect(result[1]).not_to include("<table>") expect(result[1]).not_to include("<thead>") expect(result[1]).not_to include("<tbody>") end it "splits a multi table comment" do result = dummy.parse_tables_from_comment(MULTI_TABLE_COMMENT) expect(result.size).to be(3) expect(result[0]).to include("<table>") expect(result[0]).to include("<thead>") expect(result[0]).to include("<tbody>") expect(result[0]).to include("Error") expect(result[0]).not_to include("Warning") expect(result[1]).to include("<table>") expect(result[1]).to include("<thead>") expect(result[1]).to include("<tbody>") expect(result[1]).not_to include("Error") expect(result[1]).to include("Warning") expect(result[2]).not_to include("<table>") expect(result[2]).not_to include("<thead>") expect(result[2]).not_to include("<tbody>") end end describe "#violations_from_table" do it "finds violations" do violations = dummy.violations_from_table(SINGLE_TABLE_COMMENT) expect(violations.size).to be(1) expect(violations.first).to eq( violation_factory("<p>Please include a CHANGELOG entry. You can find it at <a href=\"https://github.com/danger/danger/blob/master/CHANGELOG.md\">CHANGELOG.md</a>.</p>", sticky: true) ) end end describe "#parse_comment" do it "parse violations by kind" do violations = dummy.parse_comment(MULTI_TABLE_COMMENT) expect(violations[:error].size).to be(1) expect(violations[:warning].size).to be(1) expect(violations[:message]).to be_nil expect(violations[:error][0]).to eq( violation_factory("<p>Please include a CHANGELOG entry. You can find it at <a href=\"https://github.com/danger/danger/blob/master/CHANGELOG.md\">CHANGELOG.md</a>.</p>", sticky: true) ) expect(violations[:warning][0]).to eq(violation_factory("<p>External contributor has edited the Gemspec</p>", sticky: true)) end it "handles data-danger-table to identify danger tables" do violations = dummy.parse_comment(SINGLE_TABLE_COMMENT_NEW_TABLE_IDENTIFIER) expect(violations[:error].size).to be(1) expect(violations[:warning]).to be_nil expect(violations[:message]).to be_nil expect(violations[:error].first.message).to include("Please include a CHANGELOG") end it "parses a comment with error" do comment = comment_fixture("comment_with_error") results = dummy.parse_comment(comment) expect(results[:error].map(&:message)).to eq(["Some error"]) end it "parses a comment with error and warnings" do comment = comment_fixture("comment_with_error_and_warnings") results = dummy.parse_comment(comment) expect(results[:error].map(&:message)).to eq(["Some error"]) expect(results[:warning].map(&:message)).to eq(["First warning", "Second warning"]) end it "ignores non-sticky violations when parsing a comment" do comment = comment_fixture("comment_with_non_sticky") results = dummy.parse_comment(comment) expect(results[:warning].map(&:message)).to eq(["First warning"]) end it "parses a comment with error and warnings removing strike tag" do comment = comment_fixture("comment_with_resolved_violation") results = dummy.parse_comment(comment) expect(results[:error].map(&:message)).to eq(["Some error"]) expect(results[:warning].map(&:message)).to eq(["First warning", "Second warning"]) end end describe "#table" do let(:violation_1) { violation_factory("**Violation 1**") } let(:violation_2) do violation_factory("A [link](https://example.com)", sticky: true) end let(:violation_3) { violation_factory(%(with "double quote" and 'single quote')) } it "produces table data" do table_data = dummy.table("3 Errors", "no_entry_sign", [violation_1, violation_2, violation_3], {}) expect(table_data[:name]).to eq("3 Errors") expect(table_data[:emoji]).to eq("no_entry_sign") expect(table_data[:content].size).to be(3) expect(table_data[:content][0].message).to eq("<strong>Violation 1</strong>") expect(table_data[:content][0].sticky).to eq(false) expect(table_data[:content][1].message).to eq( "A <a href=\"https://example.com\">link</a>" ) expect(table_data[:content][1].sticky).to eq(true) expect(table_data[:content][2].message).to eq(%(with "double quote" and 'single quote')) expect(table_data[:resolved]).to be_empty expect(table_data[:count]).to be(3) end shared_examples "violation text as heredoc" do it "produces table data" do table_data = dummy.table("1 Error", "no_entry_sign", [violation], {}) expect(table_data[:name]).to eq("1 Error") expect(table_data[:emoji]).to eq("no_entry_sign") expect(table_data[:content].size).to be(1) expect(table_data[:content][0].message).to eq(heredoc_text.strip.to_s) expect(table_data[:content][0].sticky).to eq(false) expect(table_data[:resolved]).to be_empty expect(table_data[:count]).to be(1) end end context "with a heredoc text with a newline at the end" do let(:heredoc_text) { "You have made some app changes, but did not add any tests." } let(:violation) { violation_factory(heredoc) } context "with a heredoc text with a newline at the end" do let(:heredoc) do <<~MSG #{heredoc_text} MSG end it_behaves_like "violation text as heredoc" end context "with a heredoc text with two newlines at the end" do let(:heredoc) do <<~MSG #{heredoc_text} MSG end it_behaves_like "violation text as heredoc" end context "with a heredoc text with a newline at the start and end" do let(:heredoc) do <<~MSG #{heredoc_text} MSG end it_behaves_like "violation text as heredoc" end context "with a heredoc text with a newline at the start and two newlines at the end" do let(:heredoc) do <<~MSG #{heredoc_text} MSG end it_behaves_like "violation text as heredoc" end end end describe "#table_kind_from_title" do [ { title: "errors", singular: "Error", plural: "Errors", expected: :error }, { title: "warnings", singular: "Warning", plural: "Warnings", expected: :warning }, { title: "messages", singular: "Message", plural: "Messages", expected: :message } ].each do |option| describe option[:title] do it "handles singular" do kind = dummy.table_kind_from_title("1 #{option[:singular]}") expect(kind).to eq(option[:expected]) end it "handles plural" do kind = dummy.table_kind_from_title("42 #{option[:plural]}") expect(kind).to eq(option[:expected]) end it "handles lowercase" do kind = dummy.table_kind_from_title("42 #{option[:plural].downcase}") expect(kind).to eq(option[:expected]) end end end end describe "#generate_comment" do it "produces the expected comment" do comment = dummy.generate_comment( warnings: [violation_factory("This is a warning")], errors: [violation_factory("This is an error", sticky: true)], messages: [violation_factory("This is a message")], markdowns: [markdown_factory("*Raw markdown*")], danger_id: "my_danger_id", template: "github" ) expect(comment).to include('data-meta="generated_by_my_danger_id"') expect(comment).to include('<td data-sticky="true">This is an error</td>') expect(comment).to include("<td>:no_entry_sign:</td>") expect(comment).to include('<td data-sticky="false">This is a warning</td>') expect(comment).to include("<td>:warning:</td>") expect(comment).to include('<td data-sticky="false">This is a message</td>') expect(comment).to include("<td>:warning:</td>") expect(comment).to include("*Raw markdown*") end it "produces HTML that a CommonMark parser will accept inline" do ["github", "github_inline"].each do |template| comment = dummy.generate_comment( warnings: [violation_factory("This is a warning")], errors: [violation_factory("This is an error", sticky: true)], messages: [violation_factory("This is a message")], markdowns: [markdown_factory("*Raw markdown*")], danger_id: "my_danger_id", template: template ) # There should be no indented HTML tag after 2 or more newlines. expect(comment).not_to match(/(\r?\n){2}[ \t]+</) end end it "produces the expected comment when there are newlines" do comment = dummy.generate_comment( warnings: [violation_factory("This is a warning\nin two lines")], errors: [], messages: [], markdowns: [], danger_id: "my_danger_id", template: "github" ) expect(comment).to include('data-meta="generated_by_my_danger_id"') expect(comment).to include("<td data-sticky=\"false\">This is a warning<br />\nin two lines</td>") expect(comment).to include("<td>:warning:</td>") end it "produces a comment containing a summary" do comment = dummy.generate_comment( warnings: [violation_factory("Violations that are very very very very long should be truncated")], errors: [violation_factory("This is an error", sticky: true)], messages: [violation_factory("This is a message")], markdowns: [markdown_factory("*Raw markdown*")], danger_id: "my_danger_id", template: "github" ) summary = <<COMMENT <!-- 1 Error: This is an error 1 Warning: Violations that are very very ... 1 Message: This is a message 1 Markdown --> COMMENT expect(comment).to include(summary) end it "no warnings, no errors, no messages" do result = dummy.generate_comment(warnings: [], errors: [], messages: []) expect(result.gsub(/\s+/, "")).to end_with( '<palign="right"data-meta="generated_by_danger">Generatedby:no_entry_sign:<ahref="https://danger.systems/">Danger</a></p>' ) end it "supports markdown code below the summary table" do result = dummy.generate_comment(warnings: violations_factory(["ups"]), markdowns: violations_factory(["### h3"])) expect(result.gsub(/\s+/, "")).to end_with( '<table><thead><tr><thwidth="50"></th><thwidth="100%"data-danger-table="true"data-kind="Warning">1Warning</th></tr></thead><tbody><tr><td>:warning:</td><tddata-sticky="false">ups</td></tr></tbody></table>###h3<palign="right"data-meta="generated_by_danger">Generatedby:no_entry_sign:<ahref="https://danger.systems/">Danger</a></p>' ) end it "supports markdown only without a table" do result = dummy.generate_comment(markdowns: violations_factory(["### h3"])) expect(result.gsub(/\s+/, "")).to end_with( '###h3<palign="right"data-meta="generated_by_danger">Generatedby:no_entry_sign:<ahref="https://danger.systems/">Danger</a></p>' ) end it "some warnings, no errors" do result = dummy.generate_comment(warnings: violations_factory(["my warning", "second warning"]), errors: [], messages: []) expect(result.gsub(/\s+/, "")).to end_with( '<table><thead><tr><thwidth="50"></th><thwidth="100%"data-danger-table="true"data-kind="Warning">2Warnings</th></tr></thead><tbody><tr><td>:warning:</td><tddata-sticky="false">mywarning</td></tr><tr><td>:warning:</td><tddata-sticky="false">secondwarning</td></tr></tbody></table><palign="right"data-meta="generated_by_danger">Generatedby:no_entry_sign:<ahref="https://danger.systems/">Danger</a></p>' ) end it "some warnings with markdown, no errors" do warnings = violations_factory(["a markdown [link to danger](https://github.com/danger/danger)", "second **warning**"]) result = dummy.generate_comment(warnings: warnings, errors: [], messages: []) # rubocop:disable Layout/LineLength expect(result.gsub(/\s+/, "")).to end_with( '<table><thead><tr><thwidth="50"></th><thwidth="100%"data-danger-table="true"data-kind="Warning">2Warnings</th></tr></thead><tbody><tr><td>:warning:</td><tddata-sticky="false">amarkdown<ahref="https://github.com/danger/danger">linktodanger</a></td></tr><tr><td>:warning:</td><tddata-sticky="false">second<strong>warning</strong></td></tr></tbody></table><palign="right"data-meta="generated_by_danger">Generatedby:no_entry_sign:<ahref="https://danger.systems/">Danger</a></p>' ) # rubocop:enable Layout/LineLength end it "a multiline warning with markdown, no errors" do warnings = violations_factory(["a markdown [link to danger](https://github.com/danger/danger)\n\n```\nsomething\n```\n\nHello"]) result = dummy.generate_comment(warnings: warnings, errors: [], messages: []) # rubocop:disable Layout/LineLength expect(result.gsub(/\s+/, "")).to end_with( '<table><thead><tr><thwidth="50"></th><thwidth="100%"data-danger-table="true"data-kind="Warning">1Warning</th></tr></thead><tbody><tr><td>:warning:</td><tddata-sticky="false">amarkdown<ahref="https://github.com/danger/danger">linktodanger</a></p><pre><code>something</code></pre><p>Hello</td></tr></tbody></table><palign="right"data-meta="generated_by_danger">Generatedby:no_entry_sign:<ahref="https://danger.systems/">Danger</a></p>' ) # rubocop:enable Layout/LineLength end it "some warnings, some errors" do result = dummy.generate_comment(warnings: violations_factory(["my warning"]), errors: violations_factory(["some error"]), messages: []) # rubocop:disable Layout/LineLength expect(result.gsub(/\s+/, "")).to end_with( '<table><thead><tr><thwidth="50"></th><thwidth="100%"data-danger-table="true"data-kind="Error">1Error</th></tr></thead><tbody><tr><td>:no_entry_sign:</td><tddata-sticky="false">someerror</td></tr></tbody></table><table><thead><tr><thwidth="50"></th><thwidth="100%"data-danger-table="true"data-kind="Warning">1Warning</th></tr></thead><tbody><tr><td>:warning:</td><tddata-sticky="false">mywarning</td></tr></tbody></table><palign="right"data-meta="generated_by_danger">Generatedby:no_entry_sign:<ahref="https://danger.systems/">Danger</a></p>' ) # rubocop:enable Layout/LineLength end it "deduplicates previous violations" do previous_violations = { error: violations_factory(["an error", "an error"]) } result = dummy.generate_comment(warnings: [], errors: violations_factory([]), messages: [], previous_violations: previous_violations) expect(result.scan("an error").size).to eq(1) end it "includes a random compliment" do previous_violations = { error: violations_factory(["an error"]) } result = dummy.generate_comment(warnings: [], errors: violations_factory([]), messages: [], previous_violations: previous_violations) expect(result).to match(/:white_check_mark: \w+?/) end it "crosses resolved violations and changes the title" do previous_violations = { error: violations_factory(["an error"]) } result = dummy.generate_comment(warnings: [], errors: [], messages: [], previous_violations: previous_violations) expect(result.gsub(/\s+/, "")).to include('<thwidth="100%"data-danger-table="true"data-kind="Error">:white_check_mark:') expect(result.gsub(/\s+/, "")).to include('<td>:white_check_mark:</td><tddata-sticky="true"><del>anerror</del></td>') end it "uncrosses violations that were on the list and happened again" do previous_violations = { error: violations_factory(["an error"]) } result = dummy.generate_comment( warnings: [], errors: violations_factory(["an error"]), messages: [], previous_violations: previous_violations ) expect(result.gsub(/\s+/, "")).to end_with( '<table><thead><tr><thwidth="50"></th><thwidth="100%"data-danger-table="true"data-kind="Error">1Error</th></tr></thead><tbody><tr><td>:no_entry_sign:</td><tddata-sticky="false">anerror</td></tr></tbody></table><palign="right"data-meta="generated_by_danger">Generatedby:no_entry_sign:<ahref="https://danger.systems/">Danger</a></p>' ) end it "counts only unresolved violations on the title" do previous_violations = { error: violations_factory(["an error"]) } result = dummy.generate_comment(warnings: [], errors: violations_factory(["another error"]), messages: [], previous_violations: previous_violations) expect(result.gsub(/\s+/, "")).to include('<thwidth="100%"data-danger-table="true"data-kind="Error">1Error</th>') end it "needs to include generated_by_danger" do result = dummy.generate_comment(warnings: violations_factory(["my warning"]), errors: violations_factory(["some error"]), messages: []) expect(result.gsub(/\s+/, "")).to include("generated_by_danger") end it "handles a custom danger_id" do result = dummy.generate_comment(warnings: violations_factory(["my warning"]), errors: violations_factory(["some error"]), messages: [], danger_id: "another_danger") expect(result.gsub(/\s+/, "")).to include("generated_by_another_danger") end it "sets data-sticky to true when a violation is sticky" do sticky_warning = Danger::Violation.new("my warning", true) result = dummy.generate_comment(warnings: [sticky_warning], errors: [], messages: []) expect(result.gsub(/\s+/, "")).to include('tddata-sticky="true"') end it "sets data-sticky to false when a violation is not sticky" do non_sticky_warning = Danger::Violation.new("my warning", false) result = dummy.generate_comment(warnings: [non_sticky_warning], errors: [], messages: []) expect(result.gsub(/\s+/, "")).to include('tddata-sticky="false"') end it "truncates comments which would exceed githubs maximum comment length" do warnings = (1..900).map { |i| "single long warning" * rand(1..10) + i.to_s } result = dummy.generate_comment(warnings: violations_factory(warnings), errors: violations_factory([]), messages: []) expect(result.length).to be <= GITHUB_MAX_COMMENT_LENGTH expect(result).to include("has been truncated") end end describe "#generate_message_group_comment" do subject do dummy.generate_message_group_comment(message_group: message_group, danger_id: danger_id, resolved: resolved, template: template) end let(:message_group) { Danger::MessageGroup.new(file: file, line: line) } let(:file) { nil } let(:line) { nil } let(:resolved) { [] } let(:danger_id) { Base64.encode64(Random.new.bytes(10)).chomp } context "when template is bitbucket_server_message_group" do let(:template) { "bitbucket_server_message_group" } context "with one of each type of message" do before do message_group << Danger::Violation.new("Hello!", false, file, line, type: :error) message_group << Danger::Violation.new("World!", false, file, line, type: :warning) message_group << Danger::Violation.new("HOW R", false, file, line, type: :message) message_group << Danger::Markdown.new("U DOING?", file, line) end it "spits out a beautiful comment" do expect(subject).to eq <<~COMMENT :no_entry_sign: Hello! :warning: World! :blue_book: HOW R U DOING? Generated by :no_entry_sign: [Danger](https://danger.systems/ "generated_by_#{danger_id}") COMMENT end end context "with two markdowns" do before do message_group << Danger::Markdown.new("markdown one", file, line) message_group << Danger::Markdown.new("markdown two", file, line) end it "spits out a beautiful comment" do expect(subject).to eq <<~COMMENT markdown one markdown two Generated by :no_entry_sign: [Danger](https://danger.systems/ "generated_by_#{danger_id}") COMMENT end end context "without any messages" do it "outputs just the Generated line" do expect(subject).to eq <<~COMMENT Generated by :no_entry_sign: [Danger](https://danger.systems/ "generated_by_#{danger_id}") COMMENT end end end end describe "#generate_description" do it "Handles no errors or warnings" do message = dummy.generate_description(warnings: [], errors: []) expect(message).to include("All green.") end it "handles a single error and a single warning" do message = dummy.generate_description(warnings: [1], errors: [1]) expect(message).to include("⚠️ ") expect(message).to include("Error") expect(message).to include("Warning") expect(message).to include("Don't worry, everything is fixable.") end it "handles multiple errors and warning with pluralisation" do message = dummy.generate_description(warnings: [1, 2], errors: [1, 2]) expect(message).to include("⚠️ ") expect(message).to include("Errors") expect(message).to include("Warnings") expect(message).to include("Don't worry, everything is fixable.") end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/bitrise_spec.rb
spec/lib/danger/ci_sources/bitrise_spec.rb
# frozen_string_literal: true require "danger/ci_source/xcode_server" RSpec.describe Danger::Bitrise do let(:valid_env) do { "BITRISE_PULL_REQUEST" => "4", "BITRISE_IO" => "true", "GIT_REPOSITORY_URL" => "git@github.com:artsy/eigen" } end let(:invalid_env) do { "CIRCLE" => "true" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_pr?" do it "validates when the required env variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "does not validate when the required env variables are not set" do expect(described_class.validates_as_pr?(invalid_env)).to be false end it "does not validate when there isn't a PR" do valid_env["BITRISE_PULL_REQUEST"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end end describe ".validates_as_ci?" do it "validates when the required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "does not validate when the required env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end it "validates even when there is no PR" do valid_env["BITRISE_PULL_REQUEST"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end end describe "#new" do it "sets the repo_slug" do expect(source.repo_slug).to eq("artsy/eigen") end it "sets the repo_slug from a repo with dots in it", host: :github do valid_env["GIT_REPOSITORY_URL"] = "git@github.com:artsy/artsy.github.io" expect(source.repo_slug).to eq("artsy/artsy.github.io") end it "sets the repo_slug from a repo with two or more slashes in it", host: :github do valid_env["GIT_REPOSITORY_URL"] = "git@github.com:artsy/mobile/ios/artsy.github.io" expect(source.repo_slug).to eq("artsy/mobile/ios/artsy.github.io") end it "sets the repo_slug from a repo with .git in it", host: :github do valid_env["GIT_REPOSITORY_URL"] = "git@github.com:artsy/mobile/ios/artsy.github.io.git" expect(source.repo_slug).to eq("artsy/mobile/ios/artsy.github.io") end it "sets the repo_slug from a repo https url", host: :github do valid_env["GIT_REPOSITORY_URL"] = "https://github.com/artsy/ios/artsy.github.io" expect(source.repo_slug).to eq("artsy/ios/artsy.github.io") end it "sets the repo_slug from a repo https url with .git in it", host: :github do valid_env["GIT_REPOSITORY_URL"] = "https://github.com/artsy/ios/artsy.github.io.git" expect(source.repo_slug).to eq("artsy/ios/artsy.github.io") end it "sets the repo_slug from a repo without scheme", host: :github do valid_env["GIT_REPOSITORY_URL"] = "github.com/artsy/ios/artsy.github.io.git" expect(source.repo_slug).to eq("artsy/ios/artsy.github.io") end it "sets the repo_slug from a repo with .io instead of .com", host: :github do valid_env["GIT_REPOSITORY_URL"] = "git@github.company.io:artsy/ios/artsy.github.io.git" expect(source.repo_slug).to eq("artsy/ios/artsy.github.io") end it "sets the repo_slug from an url that has an ssh scheme", host: :github do valid_env["GIT_REPOSITORY_URL"] = "ssh://git@github.company.io/artsy/ios/artsy.github.io.git" expect(source.repo_slug).to eq("artsy/ios/artsy.github.io") end it "sets the repo_slug from an url that has a port in it and has ssh as a scheme", host: :github do valid_env["GIT_REPOSITORY_URL"] = "ssh://git@github.company.io:22/artsy/ios/artsy.github.io.git" expect(source.repo_slug).to eq("artsy/ios/artsy.github.io") end it "sets the pull_request_id" do expect(source.pull_request_id).to eq("4") end it "sets the repo_url", host: :github do with_git_repo(origin: "git@github.com:artsy/eigen") do expect(source.repo_url).to eq("git@github.com:artsy/eigen") end end end describe "supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end it "supports GitLab" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitLab) end it "supports BitBucket Cloud" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketCloud) end it "supports BitBucket Server" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketServer) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/circle_spec.rb
spec/lib/danger/ci_sources/circle_spec.rb
# frozen_string_literal: true require "danger/ci_source/circle" RSpec.describe Danger::CircleCI do let(:legit_pr) { "https://github.com/artsy/eigen/pulls/800" } let(:not_legit_pr) { "https://github.com/orta" } let(:valid_env) do { "CIRCLE_BUILD_NUM" => "1500", "CI_PULL_REQUEST" => legit_pr, "CIRCLE_PROJECT_USERNAME" => "artsy", "CIRCLE_PROJECT_REPONAME" => "eigen", "CIRCLE_REPOSITORY_URL" => "git@github.com:artsy/eigen.git" } end let(:invalid_env) do { "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_ci?" do it "validates when all required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates when the `CI_PULL_REQUEST` is missing" do valid_env["CI_PULL_REQUEST"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates when the `CI_PULL_REQUEST` is not legit" do valid_env["CI_PULL_REQUEST"] = not_legit_pr expect(described_class.validates_as_ci?(valid_env)).to be true end it "does not validate when all required env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when required env variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end context "with missing `CI_PULL_REQUEST` and `CIRCLE_PULL_REQUEST`" do context "and with `CIRCLE_PR_NUMBER`" do before do valid_env["CI_PULL_REQUEST"] = nil valid_env["DANGER_CIRCLE_CI_API_TOKEN"] = "testtoken" valid_env["CIRCLE_PR_NUMBER"] = "800" end it "validates when required env variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end end context "and with missing `CIRCLE_PR_NUMBER`" do before do valid_env["CI_PULL_REQUEST"] = nil valid_env["DANGER_CIRCLE_CI_API_TOKEN"] = "testtoken" build_response = JSON.parse(fixture("circle_build_response"), symbolize_names: true) allow_any_instance_of(Danger::CircleAPI).to receive(:fetch_build).with("artsy/eigen", "1500", "testtoken").and_return(build_response) end it "validates when required env variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end end end context "uses `CIRCLE_PULL_REQUEST` if available" do before do valid_env["CI_PULL_REQUEST"] = nil valid_env["CIRCLE_PULL_REQUEST"] = "https://github.com/artsy/eigen/pulls/800" end it "validates when required env variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end end it "does not validate if `CI_PULL_REQUEST` is empty" do valid_env["CI_PULL_REQUEST"] = "" expect(described_class.validates_as_pr?(invalid_env)).to be false end it "does not validate when required env variables are not set" do expect(described_class.validates_as_pr?(invalid_env)).to be false end end describe "#new" do it "does not get a PR id when it has a bad PR url" do valid_env["CI_PULL_REQUEST"] = not_legit_pr expect { source }.to raise_error RuntimeError end it "sets the repo_slug" do expect(source.repo_slug).to eq("artsy/eigen") end it "sets the pull_request_id" do expect(source.pull_request_id).to eq("800") end it "sets the repo_url" do expect(source.repo_url).to eq("git@github.com:artsy/eigen.git") end context "with missing `CI_PULL_REQUEST`" do before do build_response = JSON.parse(fixture("circle_build_response"), symbolize_names: true) allow_any_instance_of(Danger::CircleAPI).to receive(:fetch_build).with("artsy/eigen", "1500", nil).and_return(build_response) end it "sets the repo_slug" do expect(source.repo_slug).to eq("artsy/eigen") end it "sets the pull_request_id" do expect(source.pull_request_id).to eq("800") end end end describe "#supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end it "supports BitBucket Cloud" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketCloud) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/local_only_git_repo_spec.rb
spec/lib/danger/ci_sources/local_only_git_repo_spec.rb
# frozen_string_literal: true require "spec_helper" require "danger/ci_source/local_only_git_repo" RSpec.describe Danger::LocalOnlyGitRepo do def run_in_repo Dir.mktmpdir do |dir| Dir.chdir dir do `git init -b master` `git remote add origin .` File.open("#{dir}/file1", "w") {} `git add .` `git commit --no-gpg-sign -m "adding file1"` `git fetch` `git checkout -b feature_branch` File.open("#{dir}/file2", "w") {} `git add .` `git commit --no-gpg-sign -m "adding file2"` yield end end end let(:valid_env) do { "DANGER_USE_LOCAL_ONLY_GIT" => "true" } end let(:invalid_env) do { "CIRCLE" => "true" } end def source(env) described_class.new(env) end describe "validates_as_ci?" do context "when run as danger dry_run" do it "validates as CI source" do expect(described_class.validates_as_ci?(valid_env)).to be true end end it "does not validate as CI source outside danger dry_run" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe "#new" do it "sets base_commit" do run_in_repo do expect(source(valid_env).base_commit).to eq("origin/master") end end it "sets head_commit" do run_in_repo do expect(source(valid_env).head_commit).to eq("feature_branch") end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/teamcity_spec.rb
spec/lib/danger/ci_sources/teamcity_spec.rb
# frozen_string_literal: true require "danger/ci_source/teamcity" RSpec.describe Danger::TeamCity do let(:valid_env) do { "TEAMCITY_VERSION" => "42" } end let(:invalid_env) do {} end let(:source) { described_class.new(valid_env) } context "with GitHub" do before do valid_env["GITHUB_REPO_SLUG"] = "foo/bar" valid_env["GITHUB_PULL_REQUEST_ID"] = "42" valid_env["GITHUB_REPO_URL"] = "git@github.com:danger/danger.git" end describe ".validates_as_ci?" do it "validates when required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `GITHUB_PULL_REQUEST_ID` is missing" do valid_env["GITHUB_PULL_REQUEST_ID"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `GITHUB_PULL_REQUEST_ID` is empty" do valid_env["GITHUB_PULL_REQUEST_ID"] = "" expect(described_class.validates_as_ci?(valid_env)).to be true end it "doesn't validate when require env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "doesn't validate if `GITHUB_PULL_REQUEST_ID` is missing" do valid_env["GITHUB_PULL_REQUEST_ID"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate_as_pr if pull_request_repo is the empty string" do valid_env["GITHUB_PULL_REQUEST_ID"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end end describe "#new" do it "sets the pull_request_id" do expect(source.pull_request_id).to eq(42) end it "sets the repo_slug" do expect(source.repo_slug).to eq("foo/bar") end it "sets the repo_url" do expect(source.repo_url).to eq("git@github.com:danger/danger.git") end end end context "with GitLab" do before do valid_env["GITLAB_REPO_SLUG"] = "foo/bar" valid_env["GITLAB_PULL_REQUEST_ID"] = "42" valid_env["GITLAB_REPO_URL"] = "git@gitlab.com:danger/danger.git" end describe ".validates_as_ci?" do it "validates when required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `GITLAB_PULL_REQUEST_ID` is missing" do valid_env["GITLAB_PULL_REQUEST_ID"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `GITLAB_PULL_REQUEST_ID` is empty" do valid_env["GITLAB_PULL_REQUEST_ID"] = "" expect(described_class.validates_as_ci?(valid_env)).to be true end it "doesn't validate when required env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "doesn't validate if `GITLAB_PULL_REQUEST_ID` is missing" do valid_env["GITLAB_PULL_REQUEST_ID"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate_as_pr if pull_request_repo is the empty string" do valid_env["GITLAB_PULL_REQUEST_ID"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end end describe "#new" do it "sets the pull_request_id" do expect(source.pull_request_id).to eq(42) end it "sets the repo_slug" do expect(source.repo_slug).to eq("foo/bar") end it "sets the repo_url" do expect(source.repo_url).to eq("git@gitlab.com:danger/danger.git") end end end context "with Bitbucket Cloud" do before do valid_env["BITBUCKET_REPO_SLUG"] = "foo/bar" valid_env["BITBUCKET_BRANCH_NAME"] = "feature_branch" valid_env["BITBUCKET_REPO_URL"] = "git@bitbucket.com:danger/danger.git" end describe ".validates_as_ci?" do it "validates when required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `BITBUCKET_BRANCH_NAME` is missing" do valid_env["BITBUCKET_BRANCH_NAME"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `BITBUCKET_BRANCH_NAME` is empty" do valid_env["BITBUCKET_BRANCH_NAME"] = "" expect(described_class.validates_as_ci?(valid_env)).to be true end it "doesn't validate when required env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "doesn't validate if `BITBUCKET_BRANCH_NAME` is missing" do valid_env["BITBUCKET_BRANCH_NAME"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate_as_pr if `BITBUCKET_BRANCH_NAME` is the empty string" do valid_env["BITBUCKET_BRANCH_NAME"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end end describe "#new" do let(:api) { double("Danger::RequestSources::BitbucketCloudAPI") } before do allow(Danger::RequestSources::BitbucketCloudAPI).to receive(:new) { api } allow(api).to receive(:pull_request_id) { 42 } end it "sets the repo_slug" do expect(source.repo_slug).to eq("foo/bar") end it "sets the repo_url" do expect(source.repo_url).to eq("git@bitbucket.com:danger/danger.git") end it "sets the pull_request_id" do expect(source.pull_request_id).to eq(42) end context "unable to find pull request id" do before do allow(api).to receive(:pull_request_id).and_raise("Some error") end it "raises a sensible error" do expect do source.pull_request_id end.to raise_error( RuntimeError, "Failed to find a pull request for branch \"feature_branch\" on Bitbucket." ) end end end end context "with Bitbucket Server" do before do valid_env["BITBUCKETSERVER_REPO_SLUG"] = "foo/bar" valid_env["BITBUCKETSERVER_PULL_REQUEST_ID"] = "42" valid_env["BITBUCKETSERVER_REPO_URL"] = "git@bitbucketserver.com:danger/danger.git" end describe ".validates_as_ci?" do it "validates when required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `BITBUCKETSERVER_PULL_REQUEST_ID` is missing" do valid_env["BITBUCKETSERVER_PULL_REQUEST_ID"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `BITBUCKETSERVER_PULL_REQUEST_ID` is empty" do valid_env["BITBUCKETSERVER_PULL_REQUEST_ID"] = "" expect(described_class.validates_as_ci?(valid_env)).to be true end it "doesn't validate when required env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "doesn't validate if `BITBUCKETSERVER_PULL_REQUEST_ID` is missing" do valid_env["BITBUCKETSERVER_PULL_REQUEST_ID"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate_as_pr if `BITBUCKETSERVER_PULL_REQUEST_ID` is the empty string" do valid_env["BITBUCKETSERVER_PULL_REQUEST_ID"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end end describe "#new" do it "sets the repo_slug" do expect(source.repo_slug).to eq("foo/bar") end it "sets the repo_url" do expect(source.repo_url).to eq("git@bitbucketserver.com:danger/danger.git") end it "sets the pull_request_id" do expect(source.pull_request_id).to eq(42) end end end describe "#supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end it "supports GitLab" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitLab) end it "supports Bitbucket Cloud" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketCloud) end it "supports Bitbucket Server" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketServer) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/gitlab_ci_spec.rb
spec/lib/danger/ci_sources/gitlab_ci_spec.rb
# frozen_string_literal: true require "danger/ci_source/gitlab_ci" RSpec.describe Danger::GitLabCI, host: :gitlab do context "valid environment" do let(:env) { stub_env.merge("CI_MERGE_REQUEST_IID" => 28_493) } let(:ci_source) do described_class.new(env) end describe "#supported_request_sources" do it "it is gitlab" do expect( ci_source.supported_request_sources ).to eq([Danger::RequestSources::GitHub, Danger::RequestSources::GitLab]) end end context "given PR made on gitlab hosted repository" do describe ".validates_as_ci?" do it "is valid" do expect(described_class.validates_as_ci?(env)).to be(true) end end describe ".validates_as_pr?" do it "is valid" do expect(described_class.validates_as_pr?(env)).to be(true) end end describe ".determine_pull_or_merge_request_id" do context "when CI_MERGE_REQUEST_IID present in environment" do it "returns CI_MERGE_REQUEST_IID" do expect(described_class.determine_pull_or_merge_request_id({ "CI_MERGE_REQUEST_IID" => 1 })).to eq(1) end end context "when CI_COMMIT_SHA not present in environment" do it "returns 0" do expect( described_class.determine_pull_or_merge_request_id({}) ).to eq(0) end end context "when CI_COMMIT_SHA present in environment" do context "before version 10.7" do it "uses gitlab api to find merge request id" do stub_version("10.6.4") stub_merge_requests("merge_requests_response", "k0nserv%2Fdanger-test") expect(described_class.determine_pull_or_merge_request_id({ "CI_MERGE_REQUEST_PROJECT_PATH" => "k0nserv/danger-test", "CI_COMMIT_SHA" => "3333333333333333333333333333333333333333", "DANGER_GITLAB_API_TOKEN" => "a86e56d46ac78b" })).to eq(3) end end context "version 10.7 or later" do it "uses gitlab api to find merge request id" do # Arbitrary version, as tested manually, including text components to exercise the version comparison stub_version("11.10.0-rc6-ee") commit_sha = "3333333333333333333333333333333333333333" stub_commit_merge_requests("commit_merge_requests", "k0nserv%2Fdanger-test", commit_sha) expect(described_class.determine_pull_or_merge_request_id({ "CI_MERGE_REQUEST_PROJECT_PATH" => "k0nserv/danger-test", "CI_COMMIT_SHA" => commit_sha, "DANGER_GITLAB_API_TOKEN" => "a86e56d46ac78b" })).to eq(1) end end end end describe "#initialize" do it "sets the repo_slug and pull_request_id" do expect(ci_source.repo_slug).to eq("k0nserv/danger-test") expect(ci_source.pull_request_id).to eq(env["CI_MERGE_REQUEST_IID"]) end end end context "given PR made on github hosted repository" do let(:pr_num) { "24" } let(:repo_url) { "https://github.com/procore/blueprinter" } let(:repo_slug) { "procore/blueprinter" } let(:env) do stub_env.merge( { "CI_EXTERNAL_PULL_REQUEST_IID" => pr_num, "DANGER_PROJECT_REPO_URL" => repo_url } ) end describe ".validates_as_ci?" do it "is valid" do expect(described_class.validates_as_ci?(env)).to be(true) end end describe ".validates_as_pr?" do it "is valid" do expect(described_class.validates_as_pr?(env)).to be(true) end end describe ".determine_pull_or_merge_request_id" do context "when CI_MERGE_REQUEST_IID present in environment" do it "returns CI_MERGE_REQUEST_IID" do expect(described_class.determine_pull_or_merge_request_id(env)).to eq(pr_num) end end end describe "#initialize" do it "sets the repo_slug and pull_request_id" do expect(ci_source.repo_slug).to eq(repo_slug) expect(ci_source.pull_request_id).to eq(pr_num) end end end end context "valid environment on GitLab < 11.6" do let(:env) { stub_env_pre_11_6.merge("CI_MERGE_REQUEST_IID" => 28_493) } let(:ci_source) do described_class.new(env) end describe "#initialize" do it "sets the repo_slug" do expect(ci_source.repo_slug).to eq("k0nserv/danger-test") end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/jenkins_spec.rb
spec/lib/danger/ci_sources/jenkins_spec.rb
# frozen_string_literal: true require "danger/ci_source/circle" RSpec.describe Danger::Jenkins do let(:valid_env) do { "JENKINS_URL" => "Hello", "GIT_URL" => "git@github.com:danger/danger.git" } end let(:invalid_env) do { "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true" } end let(:source) { described_class.new(valid_env) } describe "errors" do it "raises an error when no env passed in" do expect { Danger::Jenkins.new(nil) }.to raise_error Danger::Jenkins::EnvNotFound end it "raises an error when empty env passed in" do expect { Danger::Jenkins.new({}) }.to raise_error Danger::Jenkins::EnvNotFound end end context "with GitHub" do before do valid_env["ghprbPullId"] = "1234" valid_env["GIT_URL"] = "https://github.com/danger/danger.git" end describe ".validates_as_ci?" do it "validates when required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `ghprbPullId` is missing" do valid_env["ghprbPullId"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `ghprbPullId` is empty" do valid_env["ghprbPullId"] = "" expect(described_class.validates_as_ci?(valid_env)).to be true end it "doesn't validate when require env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "doesn't validate if `ghprbPullId` is missing" do valid_env["ghprbPullId"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate_as_pr if `ghprbPullId` is the empty string" do valid_env["ghprbPullId"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate_as_pr if `ghprbPullId` is not a number" do valid_env["ghprbPullId"] = "false" expect(described_class.validates_as_pr?(valid_env)).to be false end end describe "#new" do it "sets the pull_request_id" do expect(source.pull_request_id).to eq("1234") end end end context "with GitLab" do before do valid_env["gitlabMergeRequestIid"] = "1234" valid_env["gitlabMergeRequestId"] = "2345" valid_env["GIT_URL"] = "https://gitlab.com/danger/danger.git" end describe ".validates_as_ci?" do it "validates when required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `gitlabMergeRequestIid` is missing" do valid_env["gitlabMergeRequestIid"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `gitlabMergeRequestId` is missing" do valid_env["gitlabMergeRequestId"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `gitlabMergeRequestIid` is empty" do valid_env["gitlabMergeRequestIid"] = "" expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `gitlabMergeRequestId` is empty" do valid_env["gitlabMergeRequestId"] = "" expect(described_class.validates_as_ci?(valid_env)).to be true end it "doesn't validate when require env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "validates if `gitlabMergeRequestIid` is missing and `gitlabMergeRequestId` is set" do valid_env["gitlabMergeRequestIid"] = nil expect(described_class.validates_as_pr?(valid_env)).to be true end it "doesn't validate_as_pr if `gitlabMergeRequestIid` is the empty string" do valid_env["gitlabMergeRequestIid"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate if `gitlabMergeRequestIid` is missing and `gitlabMergeRequestId` is missing" do valid_env["gitlabMergeRequestIid"] = nil valid_env["gitlabMergeRequestId"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate_as_pr if `gitlabMergeRequestIid` is missing and `gitlabMergeRequestId` is the empty string" do valid_env["gitlabMergeRequestIid"] = nil valid_env["gitlabMergeRequestId"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end describe "#new" do it "sets the pull_request_id" do expect(source.pull_request_id).to eq("1234") end end end end context "with multibranch pipeline" do before do valid_env["GIT_URL"] = nil valid_env["CHANGE_ID"] = "647" valid_env["CHANGE_URL"] = "https://github.com/danger/danger/pull/647" end describe ".validates_as_ci?" do it "validates when required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `CHANGE_ID` is missing" do valid_env["CHANGE_ID"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `CHANGE_ID` is empty" do valid_env["CHANGE_ID"] = "" expect(described_class.validates_as_ci?(valid_env)).to be true end it "doesn't validate when require env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "doesn't validate if `CHANGE_ID` is missing" do valid_env["CHANGE_ID"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate_as_pr if `CHANGE_ID` is the empty string" do valid_env["CHANGE_ID"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end end describe ".repo_url()" do it "gets the GitHub url" do valid_env["CHANGE_URL"] = "https://github.com/danger/danger/pull/647" expect(described_class.repo_url(valid_env)).to eq("https://github.com/danger/danger") end it "gets the GitLab url" do valid_env["CHANGE_URL"] = "https://gitlab.com/danger/danger/merge_requests/1234" expect(described_class.repo_url(valid_env)).to eq("https://gitlab.com/danger/danger") end it "gets the GitLab url containing /-/ scope" do valid_env["CHANGE_URL"] = "https://gitlab.com/danger/danger/-/merge_requests/1234" expect(described_class.repo_url(valid_env)).to eq("https://gitlab.com/danger/danger") end it "gets the BitBucket url" do valid_env["CHANGE_URL"] = "https://bitbucket.org/danger/danger/pull-requests/1" expect(described_class.repo_url(valid_env)).to eq("https://bitbucket.org/danger/danger") end it "gets the BitBucket Server url" do valid_env["CHANGE_URL"] = "https://bitbucket.example.com/projects/DANGER/repos/danger/pull-requests/1/overview" expect(described_class.repo_url(valid_env)).to eq("https://bitbucket.example.com/projects/DANGER/repos/danger") end end describe "#new" do it "sets the pull_request_id" do expect(source.pull_request_id).to eq("647") end it "sets the repo_url" do expect(source.repo_url).to eq("https://github.com/danger/danger") end end end context "Multiple remotes support" do it "gets out the repo slug from GIT_URL_1" do source = described_class.new( "JENKINS_URL" => "Hello", "GIT_URL_1" => "https://githug.com/danger/danger.git" ) expect(source.repo_slug).to eq("danger/danger") end end describe "#new" do describe "repo slug" do it "gets out a repo slug from a git+ssh repo" do expect(source.repo_slug).to eq("danger/danger") end it "gets out a repo slug from a https repo" do valid_env["GIT_URL"] = "https://gitlab.com/danger/danger.git" expect(source.repo_slug).to eq("danger/danger") end it "get out a repo slug from a repo with dot in name" do valid_env["GIT_URL"] = "https://gitlab.com/danger/danger.test.git" expect(source.repo_slug).to eq("danger/danger.test") end it "get out a repo slug from a repo with .git in name" do valid_env["GIT_URL"] = "https://gitlab.com/danger/danger.git.git" expect(source.repo_slug).to eq("danger/danger.git") end it "gets out a repo slug from a BitBucket Server" do valid_env["CHANGE_URL"] = "https://bitbucket.example.com/projects/DANGER/repos/danger/pull-requests/1/overview" expect(source.repo_slug).to eq("DANGER/danger") end it "gets out a repo slug with multiple groups ssh" do valid_env["GIT_URL"] = "git@gitlab.com:danger/systems/danger.git" expect(source.repo_slug).to eq("danger/systems/danger") end it "gets out a repo slug with multiple groups http" do valid_env["GIT_URL"] = "http://gitlab.com/danger/systems/danger.git" expect(source.repo_slug).to eq("danger/systems/danger") end it "gets out a repo slug with multiple groups https" do valid_env["GIT_URL"] = "https://gitlab.com/danger/systems/danger.git" expect(source.repo_slug).to eq("danger/systems/danger") end end end describe "#supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end it "supports GitLab" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitLab) end it "supports BitBucket Cloud" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketCloud) end it "supports BitBucket Server" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketServer) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/local_git_repo_spec.rb
spec/lib/danger/ci_sources/local_git_repo_spec.rb
# frozen_string_literal: true require "spec_helper" require "danger/ci_source/local_git_repo" require "ostruct" RSpec.describe Danger::LocalGitRepo do def run_in_repo(merge_pr: true, squash_and_merge_pr: false) Dir.mktmpdir do |dir| Dir.chdir dir do `git init -b master` `git remote add origin https://github.com/danger/danger.git` File.open("#{dir}/file1", "w") {} `git add .` `git commit --no-gpg-sign -m "adding file1"` `git checkout -b new-branch --quiet` File.open("#{dir}/file2", "w") {} `git add .` `git commit --no-gpg-sign -m "adding file2"` `git checkout master --quiet` if merge_pr `git merge new-branch --no-ff --no-gpg-sign -m "Merge pull request #1234 from new-branch"` end if squash_and_merge_pr `git merge new-branch --no-ff --no-gpg-sign -m "New branch (#1234)"` end yield end end end let(:valid_env) do { "DANGER_USE_LOCAL_GIT" => "true" } end let(:invalid_env) do { "CIRCLE" => "true" } end def source(env) described_class.new(env) end describe "validates_as_ci?" do it "validates when run by danger local" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "does not validate when run by danger local" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe "#new" do it "sets the pull_request_id" do run_in_repo do result = source(valid_env.merge!("LOCAL_GIT_PR_ID" => "1234")) expect(result.pull_request_id).to eq("1234") end end describe "repo_logs" do let(:git_sha_regex) { /\b[0-9a-f]{5,40}\b/ } it "returns the git logs correctly" do run_in_repo do result = source(valid_env) expect(result.run_git("log --oneline -1000000").split("\n")).to match_array [ /#{git_sha_regex} Merge pull request #1234 from new-branch/, /#{git_sha_regex} adding file2/, /#{git_sha_regex} adding file1/ ] end end context "with a non UTF-8 character" do let(:invalid_encoded_string) { "testing\xC2 a non UTF-8 string" } it "encodes the string correctly" do expect { invalid_encoded_string.gsub(//, "") }.to raise_error(ArgumentError) run_in_repo do File.open("file3", "w") {} `git add .` `git commit --no-gpg-sign -m "#{invalid_encoded_string}"` result = source(valid_env) logs = nil expect { logs = result.run_git("log --oneline -1000000") }.to_not raise_error expect(logs.split("\n")).to match_array [ /#{git_sha_regex} testing a non UTF-8 string/, /#{git_sha_regex} Merge pull request #1234 from new-branch/, /#{git_sha_regex} adding file2/, /#{git_sha_regex} adding file1/ ] end end end end describe "repo_slug" do it "gets the repo slug when it uses https" do run_in_repo do result = source(valid_env) expect(result.repo_slug).to eq("danger/danger") end end it "gets the repo slug when it uses git@" do run_in_repo do `git remote set-url origin git@github.com:orta/danger.git` result = source(valid_env) expect(result.repo_slug).to eq("orta/danger") end end it "gets the repo slug when it contains .git" do run_in_repo do `git remote set-url origin git@github.com:artsy/artsy.github.com.git` result = source(valid_env) expect(result.repo_slug).to eq("artsy/artsy.github.com") end end it "gets the repo slug when it starts with git://" do run_in_repo do `git remote set-url origin git://github.com:orta/danger.git` result = source(valid_env) expect(result.repo_slug).to eq("orta/danger") end end it "does not set a repo_slug if the repo has a non-gh remote" do run_in_repo do `git remote set-url origin git@git.evilcorp.com:tyrell/danger.git` expect { source(valid_env) }.to \ raise_error( RuntimeError, /danger cannot find your git remote, please set a remote. And the repository must host on GitHub.com or GitHub Enterprise./ ) end end context "enterprise github repos" do it "does set a repo slug if provided with a github enterprise host" do run_in_repo do `git remote set-url origin git@git.evilcorp.com:tyrell/danger.git` result = source(valid_env.merge!("DANGER_GITHUB_HOST" => "git.evilcorp.com")) expect(result.repo_slug).to eq("tyrell/danger") end end it "does not set a repo_slug if provided with a github_host that is different from the remote" do run_in_repo do `git remote set-url origin git@git.evilcorp.com:tyrell/danger.git` expect { source(valid_env.merge!("DANGER_GITHUB_HOST" => "git.robot.com")) }.to \ raise_error( RuntimeError, /danger cannot find your git remote, please set a remote. And the repository must host on GitHub.com or GitHub Enterprise./ ) end end end end context "multiple PRs" do def add_another_pr # Add a new PR merge commit `git checkout -b new-branch2 --quiet` File.open("file3", "w") {} `git add .` `git commit --no-gpg-sign -m "adding file2"` `git checkout master --quiet` `git merge new-branch2 --no-ff --no-gpg-sign -m "Merge pull request #1235 from new-branch"` end it "handles finding the resulting PR" do run_in_repo(merge_pr: true) do add_another_pr result = source({ "DANGER_USE_LOCAL_GIT" => "true", "LOCAL_GIT_PR_ID" => "1234" }) expect(result.pull_request_id).to eq("1234") end end end context "no incorrect PR id" do it "raise an exception" do run_in_repo do expect do source(valid_env.merge!("LOCAL_GIT_PR_ID" => "1238")) end.to raise_error( RuntimeError, "Could not find the Pull Request (1238) inside the git history for this repo." ) end end end context "no PRs" do it "raise an exception" do run_in_repo(merge_pr: false) do expect do source(valid_env) end.to raise_error( RuntimeError, "No recent Pull Requests found for this repo, danger requires at least one Pull Request for the local mode." ) end end end context "squash and merge PR" do it "works" do run_in_repo(merge_pr: false, squash_and_merge_pr: true) do result = source(valid_env) expect(result.pull_request_id).to eq "1234" end end end context "forked PR" do before { ENV["DANGER_GITHUB_API_TOKEN"] = "hi" } it "works" do spec_root = Dir.pwd client = double("Octokit::Client") allow(Octokit::Client).to receive(:new) { client } allow(client).to receive(:pull_request).with("orta/danger", "42") do JSON.parse( IO.read("#{spec_root}/spec/fixtures/ci_source/support/fork-pr.json"), object_class: OpenStruct ) end run_in_repo do fork_pr_env = { "LOCAL_GIT_PR_URL" => "https://github.com/orta/danger/pull/42" } result = source(valid_env.merge!(fork_pr_env)) expect(result).to have_attributes( repo_slug: "orta/danger", pull_request_id: "42", base_commit: "base commit sha1", head_commit: "head commit sha1" ) end end after { ENV["DANGER_GITHUB_API_TOKEN"] = nil } end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/buildkite_spec.rb
spec/lib/danger/ci_sources/buildkite_spec.rb
# frozen_string_literal: true require "danger/ci_source/buildkite" RSpec.describe Danger::Buildkite do let(:valid_env) do { "BUILDKITE" => "true", "BUILDKITE_REPO" => "git@github.com:Danger/danger.git", "BUILDKITE_PULL_REQUEST_REPO" => "git@github.com:KrauseFx/danger.git", "BUILDKITE_PULL_REQUEST" => "12" } end let(:invalid_env) do { "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_ci?" do it "validates when required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `BUILDKITE_PULL_REQUEST_REPO` is missing" do valid_env["BUILDKITE_PULL_REQUEST_REPO"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `BUILDKITE_PULL_REQUEST_REPO` is empty" do valid_env["BUILDKITE_PULL_REQUEST_REPO"] = "" expect(described_class.validates_as_ci?(valid_env)).to be true end it "doesnt validate when require env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "doesn not validate if `BUILDKITE_PULL_REQUEST_REPO` is missing" do valid_env["BUILDKITE_PULL_REQUEST_REPO"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate_as_pr if pull_request_repo is the empty string" do valid_env["BUILDKITE_PULL_REQUEST_REPO"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end end describe "#new" do describe "repo slug" do it "gets out a repo slug from a git+ssh repo" do expect(source.repo_slug).to eq("Danger/danger") end it "gets out a repo slug from a https repo" do valid_env["BUILDKITE_REPO"] = "https://github.com/Danger/danger.git" expect(source.repo_slug).to eq("Danger/danger") end it "gets out a repo slug from a repo with dots in it" do valid_env["BUILDKITE_REPO"] = "https://github.com/Danger/danger.systems.git" expect(source.repo_slug).to eq("Danger/danger.systems") end end it "sets the pull request id" do expect(source.pull_request_id).to eq("12") end end describe "#supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end it "supports GitLab" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitLab) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/drone_spec.rb
spec/lib/danger/ci_sources/drone_spec.rb
# frozen_string_literal: true require "danger/ci_source/drone" RSpec.describe Danger::Drone do describe "Drone >= 0.6" do it "validates when DRONE variable is set" do env = { "DRONE" => "true", "DRONE_REPO_NAME" => "danger", "DRONE_REPO_OWNER" => "danger", "DRONE_PULL_REQUEST" => 1 } expect(Danger::Drone.validates_as_ci?(env)).to be true end it "does not validate PR when DRONE_PULL_REQUEST is set to non int value" do env = { "CIRCLE" => "true", "DRONE_REPO_NAME" => "danger", "DRONE_REPO_OWNER" => "danger", "DRONE_PULL_REQUEST" => "maku" } expect(Danger::Drone.validates_as_pr?(env)).to be false end it "does not validate PR when DRONE_PULL_REQUEST is set to non positive int value" do env = { "CIRCLE" => "true", "DRONE_REPO_NAME" => "danger", "DRONE_REPO_OWNER" => "danger", "DRONE_PULL_REQUEST" => -1 } expect(Danger::Drone.validates_as_pr?(env)).to be false end it "gets the repo address" do env = { "DRONE_REPO_NAME" => "danger", "DRONE_REPO_OWNER" => "orta" } result = Danger::Drone.new(env) expect(result.repo_slug).to eq("orta/danger") end it "gets out a repo slug and pull request number" do env = { "DRONE" => "true", "DRONE_PULL_REQUEST" => "800", "DRONE_REPO_NAME" => "eigen", "DRONE_REPO_OWNER" => "artsy" } result = Danger::Drone.new(env) expect(result).to have_attributes( repo_slug: "artsy/eigen", pull_request_id: "800" ) end end it "does not validate when DRONE is not set" do env = { "CIRCLE" => "true" } expect(Danger::Drone.validates_as_ci?(env)).to be false end describe "Drone < 0.6" do it "validates when DRONE variable is set" do env = { "DRONE" => "true", "DRONE_REPO" => "danger/danger", "DRONE_PULL_REQUEST" => 1 } expect(Danger::Drone.validates_as_ci?(env)).to be true end it "does not validate PR when DRONE_PULL_REQUEST is set to non int value" do env = { "CIRCLE" => "true", "DRONE_REPO" => "danger/danger", "DRONE_PULL_REQUEST" => "maku" } expect(Danger::Drone.validates_as_pr?(env)).to be false end it "does not validate PR when DRONE_PULL_REQUEST is set to non positive int value" do env = { "CIRCLE" => "true", "DRONE_REPO" => "danger/danger", "DRONE_PULL_REQUEST" => -1 } expect(Danger::Drone.validates_as_pr?(env)).to be false end it "gets the repo address" do env = { "DRONE_REPO" => "orta/danger" } result = Danger::Drone.new(env) expect(result.repo_slug).to eq("orta/danger") end it "gets out a repo slug and pull request number" do env = { "DRONE" => "true", "DRONE_PULL_REQUEST" => "800", "DRONE_REPO" => "artsy/eigen" } result = Danger::Drone.new(env) expect(result).to have_attributes( repo_slug: "artsy/eigen", pull_request_id: "800" ) end end it "gets the pull request ID" do env = { "DRONE_PULL_REQUEST" => "2" } result = Danger::Drone.new(env) expect(result.pull_request_id).to eq("2") end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/azure_pipelines_spec.rb
spec/lib/danger/ci_sources/azure_pipelines_spec.rb
# frozen_string_literal: true require "danger/ci_source/azure_pipelines" RSpec.describe Danger::AzurePipelines do let(:valid_env) do { "AGENT_ID" => "4a4d3fa1-bae7-4e5f-a14a-a50b184c74aa", "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI" => "https://example.visualstudio.com", "BUILD_REPOSITORY_URI" => "https://example.visualstudio.com/_git/danger-test", "BUILD_SOURCEBRANCH" => "refs/pull/800/merge", "BUILD_REASON" => "PullRequest", "BUILD_REPOSITORY_NAME" => "danger-test", "SYSTEM_TEAMPROJECT" => "example", "SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" => "800", "BUILD_REPOSITORY_PROVIDER" => "GitHub" } end let(:invalid_env) do { "CIRCLE" => "true" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_ci?" do it "validates when the required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates when `BUILD_REPOSITORY_PROVIDER` is TfsGit" do valid_env["BUILD_REPOSITORY_PROVIDER"] = "TfsGit" expect(described_class.validates_as_ci?(valid_env)).to be true end it "doesn't validate when require env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "doesn't validate if `BUILD_REASON` is missing" do valid_env["BUILD_REASON"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate_as_pr if `BUILD_REASON` is the empty string" do valid_env["BUILD_REASON"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate when require env variables are not set" do expect(described_class.validates_as_pr?(invalid_env)).to be false end end describe "#new" do it "sets the pull_request_id" do expect(source.pull_request_id).to eq("800") end it "sets the repo_slug" do expect(source.repo_slug).to eq("danger-test") end it "sets the repo_url", host: :vsts do with_git_repo do expect(source.repo_url).to eq("https://example.visualstudio.com/_git/danger-test") end end end describe "#supported_request_sources" do it "supports VSTS" do expect(source.supported_request_sources).to include(Danger::RequestSources::VSTS) end it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/code_build_spec.rb
spec/lib/danger/ci_sources/code_build_spec.rb
# frozen_string_literal: true require "danger/ci_source/github_actions" RSpec.describe Danger::CodeBuild do let(:valid_env) do { "CODEBUILD_BUILD_ID" => "codebuild:cf613895-4a78-4456-8568-a53784fa75c5", "CODEBUILD_SOURCE_VERSION" => "pr/1234", "CODEBUILD_WEBHOOK_TRIGGER" => "pr/1234", "CODEBUILD_SOURCE_REPO_URL" => source_repo_url } end let(:env) { valid_env } let(:source_repo_url) { "https://github.com/danger/danger.git" } let(:source) { described_class.new(env) } context "with GitHub" do describe ".validates_as_ci?" do subject { described_class.validates_as_ci?(env) } context "when required env variables are set" do it "validates" do is_expected.to be true end end context "when required env variables are not set" do let(:env) { {} } it "doesn't validates" do is_expected.to be false end end end describe ".validates_as_pr?" do subject { described_class.validates_as_pr?(env) } context "when not batch build" do context "when `CODEBUILD_SOURCE_VERSION` like a 'pr/1234" do let(:env) { valid_env.merge({ "CODEBUILD_SOURCE_VERSION" => "pr/1234" }) } it "validates" do is_expected.to be true end end context "when `CODEBUILD_SOURCE_VERSION` is commit hash" do let(:env) { valid_env.merge({ "CODEBUILD_SOURCE_VERSION" => "6548dbc49fe57e1fe7507a7a4b815639a62e9f90" }) } it "doesn't validates" do is_expected.to be false end end context "when `CODEBUILD_SOURCE_VERSION` is missing" do let(:env) { valid_env.tap { |e| e.delete("CODEBUILD_SOURCE_VERSION") } } it "doesn't validates" do is_expected.to be false end end end context "when batch build" do before do valid_env["CODEBUILD_SOURCE_VERSION"] = "6548dbc49fe57e1fe7507a7a4b815639a62e9f90" valid_env["CODEBUILD_BATCH_BUILD_IDENTIFIER"] = "build1" end context "when `CODEBUILD_WEBHOOK_TRIGGER` like a 'pr/1234" do let(:env) { valid_env.merge({ "CODEBUILD_WEBHOOK_TRIGGER" => "pr/1234" }) } it "validates" do is_expected.to be true end end context "when `CODEBUILD_WEBHOOK_TRIGGER` like a 'branch/branch_name'" do let(:env) { valid_env.merge({ "CODEBUILD_WEBHOOK_TRIGGER" => "branch/branch_name" }) } it "doesn't validates" do is_expected.to be false end end context "when `CODEBUILD_WEBHOOK_TRIGGER` like a 'tag/v1.0.0'" do let(:env) { valid_env.merge({ "CODEBUILD_WEBHOOK_TRIGGER" => "tag/v1.0.0" }) } it "doesn't validates" do is_expected.to be false end end context "when `CODEBUILD_WEBHOOK_TRIGGER` is missing" do let(:env) { valid_env.tap { |e| e.delete("CODEBUILD_WEBHOOK_TRIGGER") } } it "doesn't validates" do is_expected.to be false end end end end end describe "#new" do describe "repo slug" do it "gets out a repo slug" do expect(source.repo_slug).to eq("danger/danger") end context "when `CODEBUILD_SOURCE_REPO_URL` is not ended with '.git'" do let(:source_repo_url) { "https://github.com/danger/danger" } it "also gets out a repo slug" do expect(source.repo_slug).to eq("danger/danger") end end context "when `CODEBUILD_SOURCE_REPO_URL` is hosted on github enterprise" do let(:env) { valid_env.merge({ "DANGER_GITHUB_HOST" => "github.example.com" }) } let(:source_repo_url) { "https://github.example.com/danger/danger" } it "also gets out a repo slug" do expect(source.repo_slug).to eq("danger/danger") end end end describe "pull request id" do context "when not batch build" do it "get out a pull request id" do expect(source.pull_request_id).to eq 1234 end end context "when batch build" do before do valid_env["CODEBUILD_SOURCE_VERSION"] = "6548dbc49fe57e1fe7507a7a4b815639a62e9f90" valid_env["CODEBUILD_BATCH_BUILD_IDENTIFIER"] = "build1" end it "get out a pull request id" do expect(source.pull_request_id).to eq 1234 end end end describe "repo url" do it "get out a repo url" do expect(source.repo_url).to eq "https://github.com/danger/danger" end end end describe "#supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/bitbucket_pipelines_spec.rb
spec/lib/danger/ci_sources/bitbucket_pipelines_spec.rb
# frozen_string_literal: true require "danger/ci_source/bitbucket_pipelines" RSpec.describe Danger::BitbucketPipelines do let(:valid_env) do { "BITBUCKET_BUILD_NUMBER" => "2", "BITBUCKET_PR_ID" => "4", "BITBUCKET_REPO_OWNER" => "foo", "BITBUCKET_REPO_SLUG" => "bar" } end let(:invalid_env) do { "BITRISE_IO" => "true" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_ci?" do it "validates when the required env vars are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "does not validate when the required env vars are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required env vars are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "does not validate when the required env vars are not set" do expect(described_class.validates_as_pr?(invalid_env)).to be false end end describe ".new" do it "sets the repository slug" do expect(source.repo_slug).to eq("foo/bar") expect(source.pull_request_id).to eq("4") end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/semaphore_spec.rb
spec/lib/danger/ci_sources/semaphore_spec.rb
# frozen_string_literal: true require "danger/ci_source/travis" RSpec.describe Danger::Semaphore do let(:valid_env) do { "SEMAPHORE" => "true", "SEMAPHORE_GIT_PR_NUMBER" => "800", "SEMAPHORE_GIT_REPO_SLUG" => "artsy/eigen", "SEMAPHORE_GIT_URL" => "git@github.com:artsy/eigen" } end let(:invalid_env) do { "CIRCLE" => "true" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_ci" do it "validates when the expected valid_env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates when `SEMAPHORE_GIT_PR_NUMBER` is missing" do valid_env["SEMAPHORE_GIT_PR_NUMBER"] = nil valid_env["PULL_REQUEST_NUMBER"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates when `SEMAPHORE_GIT_REPO_SLUG` is missing" do valid_env["SEMAPHORE_GIT_REPO_SLUG"] = nil valid_env["SEMAPHORE_REPO_SLUG"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "does not validated when some expected valid_env variables are missing" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the expected valid_env variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "does not validate if `SEMAPHORE_GIT_PR_NUMBER` is missing" do valid_env["SEMAPHORE_GIT_PR_NUMBER"] = nil valid_env["PULL_REQUEST_NUMBER"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "does not validate if `SEMAPHORE_GIT_PR_NUMBER` is empty" do valid_env["SEMAPHORE_GIT_PR_NUMBER"] = "" valid_env["PULL_REQUEST_NUMBER"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end it "does not validate if `SEMAPHORE_GIT_REPO_SLUG` is missing" do valid_env["SEMAPHORE_GIT_REPO_SLUG"] = nil valid_env["SEMAPHORE_REPO_SLUG"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "does not validate if `SEMAPHORE_GIT_REPO_SLUG` is empty" do valid_env["SEMAPHORE_GIT_REPO_SLUG"] = "" valid_env["SEMAPHORE_REPO_SLUG"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end end describe "#new" do it "sets the pull_request_id" do expect(source.pull_request_id).to eq("800") end it "sets the repo_slug" do expect(source.repo_slug).to eq("artsy/eigen") end it "sets the repo_url", host: :github do with_git_repo do expect(source.repo_url).to eq("git@github.com:artsy/eigen") end end end describe "#supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/xcode_cloud_spec.rb
spec/lib/danger/ci_sources/xcode_cloud_spec.rb
# frozen_string_literal: true require "danger/ci_source/xcode_cloud" RSpec.describe Danger::XcodeCloud do let(:valid_env) do { "CI_XCODEBUILD_ACTION" => "Any build action", "CI_PULL_REQUEST_NUMBER" => "999", "CI_PULL_REQUEST_SOURCE_REPO" => "danger/danger", "CI_PULL_REQUEST_HTML_URL" => "https://danger.systems" } end let(:invalid_env) do { "XCS_BOT_NAME" => "BuildaBot [danger/danger] PR #99" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_pr?" do it "validates when the required env variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "does not validate when the required env variables are not set" do expect(described_class.validates_as_pr?(invalid_env)).to be false end end describe ".validates_as_ci?" do it "validates when the required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "does not validate when the required env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe "#new" do it "sets the repo_slug" do expect(source.repo_slug).to eq("danger/danger") end it "sets the pull_request_id" do expect(source.pull_request_id).to eq("999") end it "sets the repo_url", host: :github do with_git_repo(origin: "https://danger.systems") do expect(source.repo_url).to eq("https://danger.systems") end end end describe "supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end it "supports GitLab" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitLab) end it "supports BitbucketServer" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketServer) end it "supports BitbucketCloud" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketCloud) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/screwdriver_spec.rb
spec/lib/danger/ci_sources/screwdriver_spec.rb
# frozen_string_literal: true # require "danger/ci_source/screwdriver" RSpec.describe Danger::Screwdriver do let(:valid_env) do { "SCREWDRIVER" => "true", "SD_PULL_REQUEST" => "42", "SCM_URL" => "git@github.com:danger/danger.git#branch" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_ci?" do it "validates when the required env vars are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "does not validate when the required env vars are not set" do valid_env.delete "SCREWDRIVER" expect(described_class.validates_as_ci?(valid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required env vars are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "does not validate when the required pull request is not set" do valid_env["SD_PULL_REQUEST"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "does not validate when the required repo url is not set" do valid_env["SCM_URL"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end end describe ".new" do it "sets the required attributes" do expect(source.repo_slug).to eq("danger/danger") expect(source.pull_request_id).to eq("42") expect(source.repo_url).to eq("git@github.com:danger/danger.git") end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/xcode_server_spec.rb
spec/lib/danger/ci_sources/xcode_server_spec.rb
# frozen_string_literal: true require "danger/ci_source/xcode_server" RSpec.describe Danger::XcodeServer do let(:valid_env) do { "XCS_BOT_NAME" => "BuildaBot [danger/danger] PR #17" } end let(:invalid_env) do { "CIRCLE" => "true" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_pr?" do it "validates when the required env variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "does not validate when XCS_BOT_NAME does not contain BuildaBot" do valid_env["XCS_BOT_NAME"] = "[danger/danger] PR #17" expect(described_class.validates_as_pr?(valid_env)).to be false end it "does not validate when the required env variables are not set" do expect(described_class.validates_as_pr?(invalid_env)).to be false end end describe ".validates_as_ci?" do it "validates when the required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates when `XCS_BOT_NAME` does not contain `BuildaBot`" do valid_env["XCS_BOT_NAME"] = "[danger/danger] PR #17" expect(described_class.validates_as_ci?(valid_env)).to be true end it "does not validate when the required env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe "#new" do it "sets the repo_slug" do expect(source.repo_slug).to eq("danger/danger") end it "sets the pull_request_id" do expect(source.pull_request_id).to eq("17") end it "sets the repo_url", host: :github do with_git_repo(origin: "git@github.com:artsy/eigen") do expect(source.repo_url).to eq("git@github.com:artsy/eigen") end end end describe "supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end it "supports BitbucketServer" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketServer) end it "supports BitbucketCloud" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketCloud) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/custom_ci_with_github_spec.rb
spec/lib/danger/ci_sources/custom_ci_with_github_spec.rb
# frozen_string_literal: true require "danger/ci_source/custom_ci_with_github" RSpec.describe Danger::CustomCIWithGithub do let(:valid_env) do { "CUSTOM_CI_WITH_GITHUB" => "true", "GITHUB_EVENT_NAME" => "pull_request", "GITHUB_REPOSITORY" => "danger/danger", "GITHUB_EVENT_PATH" => File.expand_path("../../../fixtures/ci_source/pull_request_event.json", __dir__) } end let(:invalid_env) do {} end let(:source) { described_class.new(valid_env) } context "with GitHub" do describe ".validates_as_ci?" do it "validates when required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "doesn't validate when require env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates if `GITHUB_EVENT_NAME` is 'pull_request" do valid_env["GITHUB_EVENT_NAME"] = "pull_request" expect(described_class.validates_as_pr?(valid_env)).to be true end it "validates if `GITHUB_EVENT_NAME` is 'pull_request_target" do valid_env["GITHUB_EVENT_NAME"] = "pull_request_target" expect(described_class.validates_as_pr?(valid_env)).to be true end it "doesn't validate if `GITHUB_EVENT_NAME` is 'push'" do valid_env["GITHUB_EVENT_NAME"] = "push" expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate if `GITHUB_EVENT_NAME` is missing" do valid_env["GITHUB_EVENT_NAME"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end end end describe "#new" do describe "repo slug" do it "gets out a repo slug" do expect(source.repo_slug).to eq("danger/danger") end end describe "pull request id" do it "get out a pull request id" do expect(source.pull_request_id).to eq 1 end end describe "repo url" do it "get out a repo url" do expect(source.repo_url).to eq "https://github.com/Codertocat/Hello-World.git" end end describe "without DANGER_GITHUB_API_TOKEN" do it "override by GITHUB_TOKEN if GITHUB_TOKEN is not empty" do valid_env["GITHUB_TOKEN"] = "github_token" source expect(valid_env["DANGER_GITHUB_API_TOKEN"]).to eq("github_token") end it "doesn't override if DANGER_GITHUB_API_TOKEN is not empty" do valid_env["DANGER_GITHUB_API_TOKEN"] = "danger_github_api_token" valid_env["GITHUB_TOKEN"] = "github_token" source expect(valid_env["DANGER_GITHUB_API_TOKEN"]).to eq("danger_github_api_token") end end end describe "#supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/appcircle_spec.rb
spec/lib/danger/ci_sources/appcircle_spec.rb
# frozen_string_literal: true require "danger/ci_source/appcircle" RSpec.describe Danger::Appcircle do let(:valid_env) do { "AC_PULL_NUMBER" => "4", "AC_APPCIRCLE" => "true", "AC_GIT_URL" => "git@github.com:artsy/eigen" } end let(:invalid_env) do { "CIRCLE" => "true" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_pr?" do it "validates when the required env variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "does not validate when the required env variables are not set" do expect(described_class.validates_as_pr?(invalid_env)).to be false end it "does not validate when there isn't a PR" do valid_env["AC_PULL_NUMBER"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end end describe ".validates_as_ci?" do it "validates when the required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "does not validate when the required env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end it "validates even when there is no PR" do valid_env["AC_PULL_NUMBER"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end end describe "#new" do it "sets the repo_slug" do expect(source.repo_slug).to eq("artsy/eigen") end it "sets the repo_slug from a repo with dots in it", host: :github do valid_env["AC_GIT_URL"] = "git@github.com:artsy/artsy.github.io" expect(source.repo_slug).to eq("artsy/artsy.github.io") end it "sets the repo_slug from a repo with two or more slashes in it", host: :github do valid_env["AC_GIT_URL"] = "git@github.com:artsy/mobile/ios/artsy.github.io" expect(source.repo_slug).to eq("artsy/mobile/ios/artsy.github.io") end it "sets the repo_slug from a repo with .git in it", host: :github do valid_env["AC_GIT_URL"] = "git@github.com:artsy/mobile/ios/artsy.github.io.git" expect(source.repo_slug).to eq("artsy/mobile/ios/artsy.github.io") end it "sets the repo_slug from a repo https url", host: :github do valid_env["AC_GIT_URL"] = "https://github.com/artsy/ios/artsy.github.io" expect(source.repo_slug).to eq("artsy/ios/artsy.github.io") end it "sets the repo_slug from a repo https url with .git in it", host: :github do valid_env["AC_GIT_URL"] = "https://github.com/artsy/ios/artsy.github.io.git" expect(source.repo_slug).to eq("artsy/ios/artsy.github.io") end it "sets the repo_slug from a repo without scheme", host: :github do valid_env["AC_GIT_URL"] = "github.com/artsy/ios/artsy.github.io.git" expect(source.repo_slug).to eq("artsy/ios/artsy.github.io") end it "sets the repo_slug from a repo with .io instead of .com", host: :github do valid_env["AC_GIT_URL"] = "git@github.company.io:artsy/ios/artsy.github.io.git" expect(source.repo_slug).to eq("artsy/ios/artsy.github.io") end it "sets the repo_slug from an url that has an ssh scheme", host: :github do valid_env["AC_GIT_URL"] = "ssh://git@github.company.io/artsy/ios/artsy.github.io.git" expect(source.repo_slug).to eq("artsy/ios/artsy.github.io") end it "sets the repo_slug from an url that has a port in it and has ssh as a scheme", host: :github do valid_env["AC_GIT_URL"] = "ssh://git@github.company.io:22/artsy/ios/artsy.github.io.git" expect(source.repo_slug).to eq("artsy/ios/artsy.github.io") end it "sets the pull_request_id" do expect(source.pull_request_id).to eq("4") end it "sets the repo_url", host: :github do with_git_repo(origin: "git@github.com:artsy/eigen") do expect(source.repo_url).to eq("git@github.com:artsy/eigen") end end end describe "supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end it "supports GitLab" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitLab) end it "supports BitBucket Cloud" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketCloud) end it "supports BitBucket Server" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketServer) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/github_actions_spec.rb
spec/lib/danger/ci_sources/github_actions_spec.rb
# frozen_string_literal: true require "danger/ci_source/github_actions" RSpec.describe Danger::GitHubActions do let(:valid_env) do { "GITHUB_ACTION" => "name_of_action", "GITHUB_EVENT_NAME" => "pull_request", "GITHUB_REPOSITORY" => "danger/danger", "GITHUB_EVENT_PATH" => File.expand_path("../../../fixtures/ci_source/pull_request_event.json", __dir__) } end let(:invalid_env) do {} end let(:source) { described_class.new(valid_env) } context "with GitHub" do describe ".validates_as_ci?" do it "validates when required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `GITHUB_ACTION` is missing" do valid_env["GITHUB_ACTION"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `GITHUB_ACTION` is empty" do valid_env["GITHUB_ACTION"] = "" expect(described_class.validates_as_ci?(valid_env)).to be true end it "doesn't validate when require env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates if `GITHUB_EVENT_NAME` is 'pull_request" do valid_env["GITHUB_EVENT_NAME"] = "pull_request" expect(described_class.validates_as_pr?(valid_env)).to be true end it "validates if `GITHUB_EVENT_NAME` is 'pull_request_target" do valid_env["GITHUB_EVENT_NAME"] = "pull_request_target" expect(described_class.validates_as_pr?(valid_env)).to be true end it "doesn't validate if `GITHUB_EVENT_NAME` is 'push'" do valid_env["GITHUB_EVENT_NAME"] = "push" expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate if `GITHUB_EVENT_NAME` is missing" do valid_env["GITHUB_EVENT_NAME"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end end end describe "#new" do describe "repo slug" do it "gets out a repo slug" do expect(source.repo_slug).to eq("danger/danger") end end describe "pull request id" do it "get out a pull request id" do expect(source.pull_request_id).to eq 1 end end describe "repo url" do it "get out a repo url" do expect(source.repo_url).to eq "https://github.com/Codertocat/Hello-World.git" end end describe "without DANGER_GITHUB_API_TOKEN" do it "override by GITHUB_TOKEN if GITHUB_TOKEN is not empty" do valid_env["GITHUB_TOKEN"] = "github_token" source expect(valid_env["DANGER_GITHUB_API_TOKEN"]).to eq("github_token") end it "doesn't override if DANGER_GITHUB_API_TOKEN is not empty" do valid_env["DANGER_GITHUB_API_TOKEN"] = "danger_github_api_token" valid_env["GITHUB_TOKEN"] = "github_token" source expect(valid_env["DANGER_GITHUB_API_TOKEN"]).to eq("danger_github_api_token") end end end describe "#supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/bamboo_spec.rb
spec/lib/danger/ci_sources/bamboo_spec.rb
# frozen_string_literal: true # require "danger/ci_source/bamboo" RSpec.describe Danger::Bamboo do let(:valid_env) do { "bamboo_buildKey" => "1", "bamboo_repository_pr_key" => "33", "bamboo_planRepository_repositoryUrl" => "git@github.com:danger/danger.git" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_ci?" do it "validates when the required env vars are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "does not validate when the required env vars are not set" do valid_env.delete "bamboo_buildKey" expect(described_class.validates_as_ci?(valid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required env vars are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "does not validate when the required pull request is not set" do valid_env["bamboo_repository_pr_key"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "does not validate when the required repo url is not set" do valid_env["bamboo_planRepository_repositoryUrl"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end end describe ".new" do it "sets the required attributes" do expect(source.repo_slug).to eq("danger/danger") expect(source.pull_request_id).to eq("33") expect(source.repo_url).to eq("git@github.com:danger/danger.git") end it "supports Bitbucket Server" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketServer) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/surf_spec.rb
spec/lib/danger/ci_sources/surf_spec.rb
# frozen_string_literal: true require "danger/ci_source/surf" RSpec.describe Danger::Surf do let(:valid_env) do { "SURF_REPO" => "https://github.com/surf-build/surf", "SURF_NWO" => "surf-build/surf", "SURF_PR_NUM" => "29" } end let(:invalid_env) do { "CIRCLE" => "true" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_ci?" do it "validates when the expected valid_env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "does not validated when some expected valid_env variables are missing" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the expected valid_env variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "does not validated when some expected valid_env variables are missing" do expect(described_class.validates_as_pr?(invalid_env)).to be false end end describe "#new" do it "sets the pull_request_id" do expect(source.pull_request_id).to eq("29") end it "sets the repo_slug" do expect(source.repo_slug).to eq("surf-build/surf") end it "sets the repo_url" do expect(source.repo_url).to eq("https://github.com/surf-build/surf") end end describe "#supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/ci_source_spec.rb
spec/lib/danger/ci_sources/ci_source_spec.rb
# frozen_string_literal: true require "danger/ci_source/ci_source" RSpec.describe Danger::CI do describe ".available_ci_sources" do it "returns list of CI subclasses" do expect(described_class.available_ci_sources.map(&:to_s)).to match_array( [ "Danger::Appcenter", "Danger::Appcircle", "Danger::AppVeyor", "Danger::AzurePipelines", "Danger::Bamboo", "Danger::BitbucketPipelines", "Danger::Bitrise", "Danger::Buddybuild", "Danger::Buildkite", "Danger::CircleCI", "Danger::Cirrus", "Danger::CodeBuild", "Danger::Codefresh", "Danger::Codemagic", "Danger::Codeship", "Danger::Concourse", "Danger::CustomCIWithGithub", "Danger::DotCi", "Danger::Drone", "Danger::GitHubActions", "Danger::GitLabCI", "Danger::Jenkins", "Danger::LocalGitRepo", "Danger::LocalOnlyGitRepo", "Danger::Screwdriver", "Danger::Semaphore", "Danger::Surf", "Danger::TeamCity", "Danger::Travis", "Danger::XcodeCloud", "Danger::XcodeServer" ] ) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/travis_spec.rb
spec/lib/danger/ci_sources/travis_spec.rb
# frozen_string_literal: true require "danger/ci_source/travis" RSpec.describe Danger::Travis do let(:valid_env) do { "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true", "TRAVIS_PULL_REQUEST" => "800", "TRAVIS_REPO_SLUG" => "artsy/eigen" } end let(:invalid_env) do { "CIRCLE" => "true" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_ci?" do it "validates when all Travis environment vars are set and Josh K says so" do expect(described_class.validates_as_ci?(valid_env)).to be true end ["TRAVIS_PULL_REQUEST", "TRAVIS_REPO_SLUG"].each do |var| it "validates when `#{var}` is missing" do valid_env[var] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates when `#{var}` is empty" do valid_env[var] = "" expect(described_class.validates_as_ci?(valid_env)).to be true end end it "does not validate when Josh K is not around" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when all Travis PR environment vars are set and Josh K says so" do expect(described_class.validates_as_pr?(valid_env)).to be true end ["TRAVIS_PULL_REQUEST", "TRAVIS_REPO_SLUG"].each do |var| it "does not validate when `#{var}` is missing" do valid_env[var] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "does not validate when `#{var}` is empty" do valid_env[var] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end end it "dost not validate when `TRAVIS_PULL_REQUEST` is `false`" do valid_env["TRAVIS_PULL_REQUEST"] = "false" expect(described_class.validates_as_pr?(valid_env)).to be false end it "does not validate if `TRAVIS_PULL_REQUEST` is empty" do valid_env["TRAVIS_PULL_REQUEST"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end end describe "#new" do it "sets the pull_request_id" do expect(source.pull_request_id).to eq("800") end it "sets the repo_slug" do expect(source.repo_slug).to eq("artsy/eigen") end it "sets the repo_url", host: :github do with_git_repo do expect(source.repo_url).to eq("git@github.com:artsy/eigen") end end end describe "#supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/buddybuild_spec.rb
spec/lib/danger/ci_sources/buddybuild_spec.rb
# frozen_string_literal: true require "danger/ci_source/buddybuild" RSpec.describe Danger::Buddybuild do let(:valid_env) do { "BUDDYBUILD_BUILD_ID" => "595be087b095370001d8e0b3", "BUDDYBUILD_PULL_REQUEST" => "4", "BUDDYBUILD_REPO_SLUG" => "palleas/Batman" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_ci?" do it "validates when the required env vars are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "does not validate when the required env vars are not set" do valid_env["BUDDYBUILD_BUILD_ID"] = nil expect(described_class.validates_as_ci?(valid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required env vars are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "does not validate when the required env vars are not set" do valid_env["BUDDYBUILD_PULL_REQUEST"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end end describe ".new" do it "sets the repository slug" do expect(source.repo_slug).to eq("palleas/Batman") expect(source.pull_request_id).to eq("4") end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/circle_api_spec.rb
spec/lib/danger/ci_sources/circle_api_spec.rb
# frozen_string_literal: true require "danger/ci_source/circle_api" RSpec.describe Danger::CircleAPI do context "with `CIRCLE_PR_NUMBER`" do let(:valid_env) do { "CIRCLE_BUILD_NUM" => "1500", "DANGER_CIRCLE_CI_API_TOKEN" => "token2", "CIRCLE_PROJECT_USERNAME" => "artsy", "CIRCLE_PROJECT_REPONAME" => "eigen", "CIRCLE_PR_NUMBER" => "800" } end it "returns correct attributes" do result = Danger::CircleCI.new(valid_env) expect(result).to have_attributes( repo_slug: "artsy/eigen", pull_request_id: "800" ) end context "and set `DANGER_GITHUB_HOST`" do it "returns correct attributes" do env = valid_env.merge!({ "DANGER_GITHUB_HOST" => "git.foobar.com" }) result = Danger::CircleCI.new(env) expect(result).to have_attributes( repo_slug: "artsy/eigen", pull_request_id: "800" ) end end end it "uses CIRCLE_PR_NUMBER if available" do env = { "CIRCLE_BUILD_NUM" => "1500", "DANGER_CIRCLE_CI_API_TOKEN" => "token2", "CIRCLE_PROJECT_USERNAME" => "artsy", "CIRCLE_PROJECT_REPONAME" => "eigen", "CIRCLE_PR_NUMBER" => "800" } result = Danger::CircleCI.new(env) expect(result).to have_attributes( repo_slug: "artsy/eigen", pull_request_id: "800" ) end it "gets out a repo slug, pull request number and commit refs when PR url is not found" do env = { "CIRCLE_BUILD_NUM" => "1500", "CIRCLE_PROJECT_USERNAME" => "artsy", "CIRCLE_PROJECT_REPONAME" => "eigen", "CIRCLE_COMPARE_URL" => "https://github.com/artsy/eigen/compare/759adcbd0d8f...13c4dc8bb61d" } build_response = JSON.parse(fixture("circle_build_response"), symbolize_names: true) allow_any_instance_of(Danger::CircleAPI).to receive(:fetch_build).with("artsy/eigen", "1500", nil).and_return(build_response) result = Danger::CircleCI.new(env) expect(result).to have_attributes( repo_slug: "artsy/eigen", pull_request_id: "2606" ) end it "uses the new token DANGER_CIRCLE_CI_API_TOKEN if available" do env = { "CIRCLE_BUILD_NUM" => "1500", "DANGER_CIRCLE_CI_API_TOKEN" => "token2", "CIRCLE_PROJECT_USERNAME" => "artsy", "CIRCLE_PROJECT_REPONAME" => "eigen" } build_response = JSON.parse(fixture("circle_build_response"), symbolize_names: true) allow_any_instance_of(Danger::CircleAPI).to receive(:fetch_build).with("artsy/eigen", "1500", "token2").and_return(build_response) result = Danger::CircleAPI.new.pull_request_url(env) expect(result).to eq("https://github.com/artsy/eigen/pull/2606") end it "uses Circle CI API to grab the url if available" do env = { "CIRCLE_BUILD_NUM" => "1500", "DANGER_CIRCLE_CI_API_TOKEN" => "token", "CIRCLE_PROJECT_USERNAME" => "artsy", "CIRCLE_PROJECT_REPONAME" => "eigen" } build_response = JSON.parse(fixture("circle_build_response"), symbolize_names: true) allow_any_instance_of(Danger::CircleAPI).to receive(:fetch_build).with("artsy/eigen", "1500", "token").and_return(build_response) result = Danger::CircleAPI.new.pull_request_url(env) expect(result).to eq("https://github.com/artsy/eigen/pull/2606") end context "build is not on a PR" do context "and api response contains an empty pr_response field" do it "tells you it's not a PR" do env = { "CIRCLE_BUILD_NUM" => "1500", "DANGER_CIRCLE_CI_API_TOKEN" => "token", "CIRCLE_PROJECT_USERNAME" => "artsy", "CIRCLE_PROJECT_REPONAME" => "eigen" } build_response = JSON.parse(fixture("circle_build_no_pr_response"), symbolize_names: true) allow_any_instance_of(Danger::CircleAPI).to receive(:fetch_build).with("artsy/eigen", "1500", "token").and_return(build_response) result = Danger::CircleAPI.new.pull_request?(env) expect(result).to be_falsy end end context "and api response contains no pr_response field" do it "tells you it's not a PR" do env = { "CIRCLE_BUILD_NUM" => "1500", "DANGER_CIRCLE_CI_API_TOKEN" => "token", "CIRCLE_PROJECT_USERNAME" => "artsy", "CIRCLE_PROJECT_REPONAME" => "eigen" } build_response = JSON.parse(fixture("circle_build_no_pr_field_response"), symbolize_names: true) allow_any_instance_of(Danger::CircleAPI).to receive(:fetch_build).with("artsy/eigen", "1500", "token").and_return(build_response) result = Danger::CircleAPI.new.pull_request?(env) expect(result).to be_falsy end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/codefresh_spec.rb
spec/lib/danger/ci_sources/codefresh_spec.rb
# frozen_string_literal: true require "danger/ci_source/codefresh" RSpec.describe Danger::Codefresh do let(:valid_env) do { "CF_BUILD_ID" => "89", "CF_BUILD_URL" => "https://g.codefresh.io//build/qwerty123456", "CF_PULL_REQUEST_NUMBER" => "41", "CF_REPO_OWNER" => "Danger", "CF_REPO_NAME" => "danger", "CF_COMMIT_URL" => "https://github.com/danger/danger/commit/qwerty123456" } end let(:invalid_env) do { "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_ci?" do it "validates when required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "doesnt validate when require env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "doesn not validate if `CF_PULL_REQUEST_NUMBER` is missing" do valid_env["CF_PULL_REQUEST_NUMBER"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "doesn't validate_as_pr if `CF_PULL_REQUEST_NUMBER` is the empty string" do valid_env["CF_PULL_REQUEST_NUMBER"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end end describe ".repo_slug" do it "sets the repo slug" do expect(source.repo_slug).to eq("danger/danger") end it "returns empty string for slug if no owner given" do valid_env["CF_REPO_OWNER"] = nil expect(source.repo_slug).to eq("") end it "returns empty string for slug if no name given" do valid_env["CF_REPO_NAME"] = nil expect(source.repo_slug).to eq("") end end describe ".repo_url" do it "sets the pull request url" do expect(source.repo_url).to eq("https://github.com/danger/danger") end it "returns empty string if no commit URL given" do valid_env["CF_COMMIT_URL"] = nil expect(source.repo_url).to eq("") end end describe "#new" do it "sets the pull request id" do expect(source.pull_request_id).to eq("41") end end describe "#supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/appveyor_spec.rb
spec/lib/danger/ci_sources/appveyor_spec.rb
# frozen_string_literal: true require "danger/ci_source/appveyor" RSpec.describe Danger::AppVeyor do let(:valid_env) do { "APPVEYOR_PULL_REQUEST_NUMBER" => "2", "APPVEYOR" => "true", "APPVEYOR_REPO_NAME" => "artsy/eigen" } end let(:invalid_env) do { "BITRISE_IO" => "true" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_pr?" do it "validates when the required env variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "does not validate when the required env variables are not set" do expect(described_class.validates_as_pr?(invalid_env)).to be false end it "does not validate when there isn't a PR" do valid_env["APPVEYOR_PULL_REQUEST_NUMBER"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end end describe ".validates_as_ci?" do it "validates when the required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "does not validate when the required env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end it "validates even when there is no PR" do valid_env["APPVEYOR_PULL_REQUEST_NUMBER"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end end describe "#new" do it "sets the repo_slug" do expect(source.repo_slug).to eq("artsy/eigen") end it "sets the pull_request_id" do expect(source.pull_request_id).to eq("2") end it "sets the repo_url", host: :github do with_git_repo(origin: "git@github.com:artsy/eigen") do expect(source.repo_url).to eq("git@github.com:artsy/eigen") end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/codemagic_spec.rb
spec/lib/danger/ci_sources/codemagic_spec.rb
# frozen_string_literal: true require "danger/ci_source/codemagic" RSpec.describe Danger::Codemagic do let(:valid_env) do { "FCI_PULL_REQUEST_NUMBER" => "4", "FCI_PROJECT_ID" => "1234", "FCI_REPO_SLUG" => "konsti/Batman" } end let(:invalid_env) do { "CIRCLE" => "true" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_pr?" do it "validates when the required env variables are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end it "does not validate when the required env variables are not set" do expect(described_class.validates_as_pr?(invalid_env)).to be false end it "does not validate when there isn't a PR" do valid_env["FCI_PULL_REQUEST_NUMBER"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end end describe ".validates_as_ci?" do it "validates when the required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "does not validate when the required env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end it "validates even when there is no PR" do valid_env["FCI_PULL_REQUEST_NUMBER"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end end describe "#new" do it "sets the repo_slug" do expect(source.repo_slug).to eq("konsti/Batman") end it "sets the pull_request_id" do expect(source.pull_request_id).to eq("4") end end describe "supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end it "supports GitLab" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitLab) end it "supports BitBucket Cloud" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketCloud) end it "supports BitBucket Server" do expect(source.supported_request_sources).to include(Danger::RequestSources::BitbucketServer) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/concourse_spec.rb
spec/lib/danger/ci_sources/concourse_spec.rb
# frozen_string_literal: true require "danger/ci_source/concourse" RSpec.describe Danger::Concourse do let(:valid_env) do { "CONCOURSE" => "true", "PULL_REQUEST_ID" => "800", "REPO_SLUG" => "artsy/eigen" } end let(:source) { described_class.new(valid_env) } describe ".validates_as_ci?" do it "validates when all Concourse environment vars are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end ["PULL_REQUEST_ID", "REPO_SLUG"].each do |var| it "validates when `#{var}` is missing" do valid_env[var] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates when `#{var}` is empty" do valid_env[var] = "" expect(described_class.validates_as_ci?(valid_env)).to be true end end end describe ".validates_as_pr?" do it "validates when all Concourse PR environment vars are set" do expect(described_class.validates_as_pr?(valid_env)).to be true end ["PULL_REQUEST_ID", "REPO_SLUG"].each do |var| it "does not validate when `#{var}` is missing" do valid_env[var] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end it "does not validate when `#{var}` is empty" do valid_env[var] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end end it "dost not validate when `PULL_REQUEST_ID` is `false`" do valid_env["PULL_REQUEST_ID"] = "false" expect(described_class.validates_as_pr?(valid_env)).to be false end it "does not validate if `PULL_REQUEST_ID` is empty" do valid_env["PULL_REQUEST_ID"] = "" expect(described_class.validates_as_pr?(valid_env)).to be false end it "does not validate if `PULL_REQUEST_ID` is not a int" do valid_env["PULL_REQUEST_ID"] = "pulls" expect(described_class.validates_as_pr?(valid_env)).to be false end end describe "#new" do it "sets the pull_request_id" do expect(source.pull_request_id).to eq("800") end it "sets the repo_slug" do expect(source.repo_slug).to eq("artsy/eigen") end it "sets the repo_url", host: :github do with_git_repo do expect(source.repo_url).to eq("git@github.com:artsy/eigen") end end end describe "#supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/dotci_spec.rb
spec/lib/danger/ci_sources/dotci_spec.rb
# frozen_string_literal: true require "danger/ci_source/circle" RSpec.describe Danger::DotCi do let(:valid_env) do { "DOTCI" => "true", "DOTCI_INSTALL_PACKAGES_GIT_CLONE_URL" => "git@github.com:danger/danger.git", "DOTCI_PULL_REQUEST" => "1234" } end let(:invalid_env) do { "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true" } end let(:source) { described_class.new(valid_env) } context "with GitHub" do before do valid_env["DOTCI_PULL_REQUEST"] = "1234" end describe ".validates_as_ci?" do it "validates when required env variables are set" do expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `DOTCI_PULL_REQUEST` is missing" do valid_env["DOTCI_PULL_REQUEST"] = nil expect(described_class.validates_as_ci?(valid_env)).to be true end it "validates even when `DOTCI_PULL_REQUEST` is empty" do valid_env["DOTCI_PULL_REQUEST"] = "" expect(described_class.validates_as_ci?(valid_env)).to be true end it "doesn't validate when require env variables are not set" do expect(described_class.validates_as_ci?(invalid_env)).to be false end end describe ".validates_as_pr?" do it "validates when the required variables are set" do valid_env["DOTCI_PULL_REQUEST"] = "1234" expect(described_class.validates_as_pr?(valid_env)).to be true end it "doesn't validate if `DOTCI_PULL_REQUEST` is missing" do valid_env["DOTCI_PULL_REQUEST"] = nil expect(described_class.validates_as_pr?(valid_env)).to be false end end end describe "#new" do describe "repo slug" do it "gets out a repo slug from a git+ssh repo" do expect(source.repo_slug).to eq("danger/danger") end it "gets out a repo slug from a https repo" do valid_env["DOTCI_INSTALL_PACKAGES_GIT_CLONE_URL"] = "https://gitlab.com/danger/danger.git" expect(source.repo_slug).to eq("danger/danger") end it "get out a repo slug from a repo with dot in name" do valid_env["DOTCI_INSTALL_PACKAGES_GIT_CLONE_URL"] = "https://gitlab.com/danger/danger.test.git" expect(source.repo_slug).to eq("danger/danger.test") end it "get out a repo slug from a repo with .git in name" do valid_env["DOTCI_INSTALL_PACKAGES_GIT_CLONE_URL"] = "https://gitlab.com/danger/danger.git.git" expect(source.repo_slug).to eq("danger/danger.git") end end end describe "#supported_request_sources" do it "supports GitHub" do expect(source.supported_request_sources).to include(Danger::RequestSources::GitHub) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/support/pull_request_finder_spec.rb
spec/lib/danger/ci_sources/support/pull_request_finder_spec.rb
# frozen_string_literal: true require "danger/ci_source/support/pull_request_finder" RSpec.describe Danger::PullRequestFinder do def finder(pull_request_id: "", logs: nil, repo_slug: "danger/danger", remote: "false", remote_url: "") described_class.new( pull_request_id, repo_slug, remote: remote, git_logs: logs, remote_url: remote_url ) end def merge_pull_request_log IO.read("spec/fixtures/ci_source/support/danger-git.log") end def squash_and_merge_log IO.read("spec/fixtures/ci_source/support/swiftweekly.github.io-git.log") end def two_kinds_of_merge_log IO.read("spec/fixtures/ci_source/support/two-kinds-of-merge-both-present.log") end def open_pull_requests_info require "ostruct" JSON.parse( IO.read("spec/fixtures/ci_source/support/danger_danger_pr_518.json"), object_class: OpenStruct ) end describe "#new" do it "translates $remote into boolean" do expect(finder(remote: "true")).to have_instance_variables( "@remote" => true ) end end describe "#call" do context "not specified Pull Request ID" do context "merge pull request type Pull Request" do it "returns correct Pull Request ID and SHA1" do result = finder(logs: merge_pull_request_log).call expect(result.pull_request_id).to eq "557" expect(result.sha).to eq "bde9ea7" end end context "squash and merge type Pull Request" do it "returns correct Pull Request ID and SHA1" do result = finder(logs: squash_and_merge_log).call expect(result.pull_request_id).to eq "89" expect(result.sha).to eq "129045f" end end end context "specify Pull Request ID" do context "merge pull request type Pull Request" do it "returns correct Pull Request ID and SHA1" do result = finder(pull_request_id: "556", logs: merge_pull_request_log).call expect(result.pull_request_id).to eq "556" expect(result.sha).to eq "0cd9198" end end context "squash and merge type Pull Request" do it "returns correct Pull Request ID and SHA1" do result = finder(pull_request_id: "77", logs: squash_and_merge_log).call expect(result.pull_request_id).to eq "77" expect(result.sha).to eq "3f7047a" end end end context "merged and squash-and-merged both present" do it "returns the most recent one" do result = finder(pull_request_id: "2", logs: two_kinds_of_merge_log).call expect(result.pull_request_id).to eq "2" expect(result.sha).to eq "9f8c75a" end end context "with open Pull Request" do before { ENV["DANGER_GITHUB_API_TOKEN"] = "hi" } it "returns the opened Pull Request info" do client = double("Octokit::Client") allow(Octokit::Client).to receive(:new) { client } allow(client).to receive(:pull_request).with("danger/danger", "518") do open_pull_requests_info end result = finder(pull_request_id: "518", logs: "not important here", remote: "true").call expect(result.pull_request_id).to eq "518" expect(result.head).to eq "pr 518 head commit sha1" expect(result.base).to eq "pr 518 base commit sha1" end end context "specify api endpoint of octokit client" do before { ENV["DANGER_GITHUB_API_TOKEN"] = "hi" } it "By DANGER_GITHUB_API_HOST" do ENV["DANGER_GITHUB_API_HOST"] = "https://enterprise.artsy.net" allow(Octokit::Client).to receive(:new).with( access_token: ENV["DANGER_GITHUB_API_TOKEN"], api_endpoint: "https://enterprise.artsy.net" ) { spy("Octokit::Client") } finder(pull_request_id: "42", remote: true, logs: "not important").call end it "fallbacks to DANGER_GITHUB_API_BASE_URL" do ENV["DANGER_GITHUB_API_BASE_URL"] = "https://enterprise.artsy.net" allow(Octokit::Client).to receive(:new).with( access_token: ENV["DANGER_GITHUB_API_TOKEN"], api_endpoint: "https://enterprise.artsy.net" ) { spy("Octokit::Client") } finder(pull_request_id: "42", remote: true, logs: "not important").call end end context "with bearer_token" do before { ENV["DANGER_GITHUB_BEARER_TOKEN"] = "hi" } it "creates clients with bearer_token" do allow(Octokit::Client).to receive(:new).with( bearer_token: ENV["DANGER_GITHUB_BEARER_TOKEN"], api_endpoint: be_a(String) ) { spy("Octokit::Client") } finder(pull_request_id: "42", remote: true, logs: "not important").call end end after do ENV["DANGER_GITHUB_API_TOKEN"] = nil ENV["DANGER_GITHUB_BEARER_TOKEN"] = nil ENV["DANGER_GITHUB_API_HOST"] = nil ENV["DANGER_GITHUB_API_BASE_URL"] = nil end end describe "#find_scm_provider" do def find_scm_provider(url) finder(remote: "true").send(:find_scm_provider, url) end it "detects url for bitbucket cloud" do url = "https://bitbucket.org/ged/ruby-pg/pull-requests/42" expect(find_scm_provider(url)).to eq :bitbucket_cloud end it "detects url for bitbucket server" do url = "https://example.com/bitbucket/projects/Test/repos/test/pull-requests/1946" expect(find_scm_provider(url)).to eq :bitbucket_server end it "detects url for bitbucket github" do url = "http://www.github.com/torvalds/linux/pull/42" expect(find_scm_provider(url)).to eq :github end it "defaults to github when unknown url" do url = "http://www.default-url.com/" expect(find_scm_provider(url)).to eq :github end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/support/find_repo_info_from_logs_spec.rb
spec/lib/danger/ci_sources/support/find_repo_info_from_logs_spec.rb
# frozen_string_literal: true require "danger/ci_source/support/find_repo_info_from_logs" RSpec.describe Danger::FindRepoInfoFromLogs do describe "#call" do it "returns repo slug from logs" do remote_logs = IO.read("spec/fixtures/ci_source/support/remote.log") finder = described_class.new("github.com", remote_logs) result = finder.call expect(result.slug).to eq "danger/danger" end context "specify GitHub Enterprise URL" do it "returns repo slug from logs" do remote_logs = IO.read("spec/fixtures/ci_source/support/enterprise-remote.log") finder = described_class.new("artsyhub.com", remote_logs) result = finder.call expect(result.slug).to eq "enterdanger/enterdanger" end end context "specify remote in https" do it "returns repo slug from logs" do remote_logs = IO.read("spec/fixtures/ci_source/support/https-remote.log") finder = described_class.new("github.com", remote_logs) result = finder.call expect(result.slug).to eq "danger/danger" end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/ci_sources/support/find_repo_info_from_url_spec.rb
spec/lib/danger/ci_sources/support/find_repo_info_from_url_spec.rb
# frozen_string_literal: true require "danger/ci_source/support/find_repo_info_from_url" RSpec.describe Danger::FindRepoInfoFromURL do describe "#call" do context "no match" do it "returns nil" do result = described_class.new("https://danger.systems").call expect(result).to be nil end end end context "GitHub" do it "https works" do result = described_class.new("https://github.com/torvalds/linux/pull/42").call expect(result).to have_attributes( slug: "torvalds/linux", id: "42" ) end it "http with www works" do result = described_class.new("http://www.github.com/torvalds/linux/pull/42").call expect(result).to have_attributes( slug: "torvalds/linux", id: "42" ) end end context "GitLab" do it "works with trailing slash" do result = described_class.new("https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/42/").call expect(result).to have_attributes( slug: "gitlab-org/gitlab-ce", id: "42" ) end it "works with two trailing slashes" do result = described_class.new("https://gitlab.com/gitlab-org/gitlab-group/gitlab-ce/merge_requests/42/").call expect(result).to have_attributes( slug: "gitlab-org/gitlab-group/gitlab-ce", id: "42" ) end it "works with the /-/ pattern" do result = described_class.new("https://gitlab.com/gitlab-org/gitlab-ce/-/merge_requests/42").call expect(result).to have_attributes( slug: "gitlab-org/gitlab-ce", id: "42" ) end end context "Bitbucket" do context "bitbucket.org" do it "works with regular url" do result = described_class.new("https://bitbucket.org/ged/ruby-pg/pull-requests/42").call expect(result).to have_attributes( slug: "ged/ruby-pg", id: "42" ) end it "works with another url" do result = described_class.new("https://bitbucket.org/some-org/awesomerepo/pull-requests/1324").call expect(result).to have_attributes( slug: "some-org/awesomerepo", id: "1324" ) end it "works with trailing slash" do result = described_class.new("https://bitbucket.org/some-org/awesomerepo/pull-requests/1324/").call expect(result).to have_attributes( slug: "some-org/awesomerepo", id: "1324" ) end it "works with trailing information" do result = described_class.new("https://bitbucket.org/some-org/awesomerepo/pull-requests/1324/update-compile-targetsdk-to-28/diff").call expect(result).to have_attributes( slug: "some-org/awesomerepo", id: "1324" ) end end context "bitbucket.com" do it "works with http + trailing slash" do result = described_class.new("http://www.bitbucket.com/ged/ruby-pg/pull-requests/42/").call expect(result).to have_attributes( slug: "ged/ruby-pg", id: "42" ) end end end context "Bitbucket Server" do it "works" do result = described_class.new("https://example.com/bitbucket/projects/Test/repos/test/pull-requests/1946").call expect(result).to have_attributes( slug: "Test/test", id: "1946" ) end it "works with http + trailing slash" do result = described_class.new("http://example.com/bitbucket/projects/Test/repos/test/pull-requests/1946/").call expect(result).to have_attributes( slug: "Test/test", id: "1946" ) end end context "Azure Pipelines" do it "legacy URL format works" do result = described_class.new("https://example.visualstudio.com/Test/_git/test/pullrequest/1946").call expect(result).to have_attributes( slug: "test", id: "1946" ) end it "new URL format works" do result = described_class.new("https://dev.azure.com/example/Test/_git/test/pullrequest/1946").call expect(result).to have_attributes( slug: "test", id: "1946" ) end it "legacy URL format works with http + trailing slash" do result = described_class.new("http://example.visualstudio.com/Test/_git/test/pullrequest/1946/").call expect(result).to have_attributes( slug: "test", id: "1946" ) end it "new URL format works with http + trailing slash" do result = described_class.new("http://dev.azure.com/example/Test/_git/test/pullrequest/1946/").call expect(result).to have_attributes( slug: "test", id: "1946" ) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/commands/staging_spec.rb
spec/lib/danger/commands/staging_spec.rb
# frozen_string_literal: true require "danger/commands/staging" require "open3" RSpec.describe Danger::Staging do context "prints help" do it "danger staging --help flag prints help" do stdout, = Open3.capture3("danger staging -h") expect(stdout).to include "Usage" end it "danger staging -h prints help" do stdout, = Open3.capture3("danger staging -h") expect(stdout).to include "Usage" end end describe ".options" do it "contains extra options for staging command" do result = described_class.options expect(result).to include ["--pry", "Drop into a Pry shell after evaluating the Dangerfile."] end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/commands/mr_spec.rb
spec/lib/danger/commands/mr_spec.rb
# frozen_string_literal: true require "danger/commands/mr" require "open3" RSpec.describe Danger::MR do context "prints help" do it "danger mr --help flag prints help" do stdout, = Open3.capture3("danger mr -h") expect(stdout).to include "Usage" end end describe ".summary" do it "returns the summary for MR command" do result = described_class.summary expect(result).to eq "Run the Dangerfile locally against GitLab Merge Requests. Does not post to the MR. Usage: danger mr <URL>" end end context "takes the first argument as MR URL" do it "works" do argv = CLAide::ARGV.new(["https://gitlab.com/gitlab-org/gitlab-ce/-/merge_requests/42"]) result = described_class.new(argv) expect(result).to have_instance_variables( "@mr_url" => "https://gitlab.com/gitlab-org/gitlab-ce/-/merge_requests/42" ) end end describe ".options" do it "contains extra options for MR command" do result = described_class.options expect(result).to include ["--clear-http-cache", "Clear the local http cache before running Danger locally."] expect(result).to include ["--pry", "Drop into a Pry shell after evaluating the Dangerfile."] expect(result).to include ["--dangerfile=<path/to/dangerfile>", "The location of your Dangerfile"] end it "dangerfile can be set" do argv = CLAide::ARGV.new(["--dangerfile=/Users/Orta/Dangerfile"]) allow(File).to receive(:exist?) { true } result = described_class.new(argv) expect(result).to have_instance_variables( "@dangerfile_path" => "/Users/Orta/Dangerfile" ) end end context "default options" do it "mr url is nil and clear_http_cache defaults to false" do argv = CLAide::ARGV.new([]) result = described_class.new(argv) expect(result).to have_instance_variables( "@mr_url" => nil, "@clear_http_cache" => false ) end end context "#run" do let(:env_double) { instance_double("Danger::EnvironmentManager") } let(:request_source_double) { instance_double("Danger::RequestSources::RequestSource") } it "does not post to the mr" do allow(Danger::EnvironmentManager).to receive(:new).and_return(env_double) allow(env_double).to receive(:request_source).and_return(request_source_double) allow(request_source_double).to receive(:update_pull_request!) argv = CLAide::ARGV.new(["https://gitlab.com/gitlab-org/gitlab-ce/-/merge_requests/42"]) result = described_class.new(argv) expect(request_source_double).not_to have_received(:update_pull_request!) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/commands/dry_run_spec.rb
spec/lib/danger/commands/dry_run_spec.rb
# frozen_string_literal: true require "danger/commands/dry_run" require "open3" RSpec.describe Danger::DryRun do context "prints help" do it "danger dry_run --help flag prints help" do stdout, = Open3.capture3("danger dry_run -h") expect(stdout).to include "Usage" end it "danger dry_run -h prints help" do stdout, = Open3.capture3("danger dry-run -h") expect(stdout).to include "Usage" end end describe ".options" do it "contains extra options for local command" do result = described_class.options expect(result).to include ["--pry", "Drop into a Pry shell after evaluating the Dangerfile."] end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/commands/pr_spec.rb
spec/lib/danger/commands/pr_spec.rb
# frozen_string_literal: true require "danger/commands/pr" require "open3" RSpec.describe Danger::PR do context "prints help" do it "danger pr --help flag prints help" do stdout, = Open3.capture3("danger pr -h") expect(stdout).to include "Usage" end it "danger pr -h prints help" do stdout, = Open3.capture3("danger pr -h") expect(stdout).to include "Usage" end end describe ".summary" do it "returns the summary for PR command" do result = described_class.summary expect(result).to eq "Run the Dangerfile locally against Pull Requests (works with forks, too). Does not post to the PR. Usage: danger pr <URL>" end end context "takes the first argument as PR URL" do it "works" do argv = CLAide::ARGV.new(["https://github.com/artsy/eigen/pull/1899"]) result = described_class.new(argv) expect(result).to have_instance_variables( "@pr_url" => "https://github.com/artsy/eigen/pull/1899" ) end end describe ".options" do it "contains extra options for PR command" do result = described_class.options expect(result).to include ["--clear-http-cache", "Clear the local http cache before running Danger locally."] expect(result).to include ["--pry", "Drop into a Pry shell after evaluating the Dangerfile."] expect(result).to include ["--dangerfile=<path/to/dangerfile>", "The location of your Dangerfile"] expect(result).to include ["--verify-ssl", "Verify SSL in Octokit"] end it "dangerfile can be set" do argv = CLAide::ARGV.new(["--dangerfile=/Users/Orta/Dangerfile"]) allow(File).to receive(:exist?) { true } result = described_class.new(argv) expect(result).to have_instance_variables( "@dangerfile_path" => "/Users/Orta/Dangerfile" ) end end context "default options" do it "pr url is nil, clear_http_cache defaults to false and verify-ssl defaults to true" do argv = CLAide::ARGV.new([]) result = described_class.new(argv) expect(result).to have_instance_variables( "@pr_url" => nil, "@clear_http_cache" => false, "@verify_ssl" => true ) end end context "#run" do let(:env_double) { instance_double("Danger::EnvironmentManager") } let(:request_source_double) { instance_double("Danger::RequestSources::RequestSource") } it "does not post to the pr" do allow(Danger::EnvironmentManager).to receive(:new).and_return(env_double) allow(env_double).to receive(:request_source).and_return(request_source_double) allow(request_source_double).to receive(:update_pull_request!) argv = CLAide::ARGV.new(["https://github.com/danger/danger/pull/1366"]) result = described_class.new(argv) expect(request_source_double).not_to have_received(:update_pull_request!) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/commands/runner_spec.rb
spec/lib/danger/commands/runner_spec.rb
# frozen_string_literal: true require "danger/commands/runner" require "danger/danger_core/executor" RSpec.describe Danger::Runner do context "without Dangerfile" do it "raises error" do argv = CLAide::ARGV.new([]) Dir.mktmpdir do |dir| Dir.chdir dir do runner = described_class.new(argv) expect { runner.validate! }.to raise_error(StandardError, /Could not find a Dangerfile./) end end end end context "default options" do it "sets instance variables accordingly" do argv = CLAide::ARGV.new([]) runner = described_class.new(argv) ui = runner.instance_variable_get(:"@cork") expect(runner).to have_instance_variables( "@dangerfile_path" => "Dangerfile", "@base" => nil, "@head" => nil, "@fail_on_errors" => false, "@fail_if_no_pr" => false, "@danger_id" => "danger", "@new_comment" => nil ) expect(ui).to be_a Cork::Board expect(ui).to have_instance_variables( "@silent" => false, "@verbose" => false ) end end context "colored output" do before do expect(Danger::Executor).to receive(:new) { executor } expect(executor).to receive(:run) { "Colored message".red } end after { Colored2.enable! } # reset to expected value to avoid false positives in other tests let(:argv) { [] } let(:runner) { described_class.new(CLAide::ARGV.new(argv)) } let(:executor) { double("Executor") } it "adds ansi codes to strings" do expect(runner.run).to eq "\e[31mColored message\e[0m" end context "when no-ansi is specified" do let(:argv) { ["--no-ansi"] } it "does not add ansi codes to strings" do expect(runner.run).to eq "Colored message" end end end describe "#run" do it "invokes Executor" do argv = CLAide::ARGV.new([]) runner = described_class.new(argv) executor = double("Executor") expect(Danger::Executor).to receive(:new) { executor } expect(executor).to receive(:run).with( base: nil, head: nil, dangerfile_path: "Dangerfile", danger_id: "danger", new_comment: nil, fail_on_errors: false, fail_if_no_pr: false, remove_previous_comments: nil ) runner.run end context "with custom CLI options passed in" do before { IO.write("MyDangerfile", "") } it "overrides default options" do argv = CLAide::ARGV.new( [ "--base=my-base", "--head=my-head", "--dangerfile=MyDangerfile", "--danger_id=my-danger-id", "--new-comment", "--fail-on-errors=true", "--fail-if-no-pr=true", "--remove-previous-comments" ] ) runner = described_class.new(argv) executor = double("Executor") expect(Danger::Executor).to receive(:new) { executor } expect(executor).to receive(:run).with( base: "my-base", head: "my-head", dangerfile_path: "MyDangerfile", danger_id: "my-danger-id", new_comment: true, fail_on_errors: "true", fail_if_no_pr: "true", remove_previous_comments: true ) runner.run end after { FileUtils.rm("MyDangerfile") } end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/commands/init_spec.rb
spec/lib/danger/commands/init_spec.rb
# frozen_string_literal: true require "danger/commands/init" RSpec.describe Danger::Init do describe "#current_repo_slug" do let(:command) { Danger::Init.new CLAide::ARGV.new([]) } context "with git url" do it "returns correct results" do url = "git@github.com:author/repo.git" allow_any_instance_of(Danger::GitRepo).to receive(:origins).and_return(url) expect(command.current_repo_slug).to eq "author/repo" end end context "with github pages url" do it "returns correct results" do url = "https://github.com/author/repo.github.io.git" allow_any_instance_of(Danger::GitRepo).to receive(:origins).and_return(url) expect(command.current_repo_slug).to eq "author/repo.github.io" end end context "with other url" do it "returns [Your/Repo]" do url = "http://example.com" allow_any_instance_of(Danger::GitRepo).to receive(:origins).and_return(url) expect(command.current_repo_slug).to eq "[Your/Repo]" end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/commands/plugin_json_spec.rb
spec/lib/danger/commands/plugin_json_spec.rb
# frozen_string_literal: true require "danger/commands/plugins/plugin_json" RSpec.describe Danger::PluginJSON do after do Danger::Plugin.clear_external_plugins end it "outputs a plugins documentation as json" do expect do described_class.run(["spec/fixtures/plugins/example_fully_documented.rb"]) end.to output(/DangerProselint/).to_stdout end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/commands/local_spec.rb
spec/lib/danger/commands/local_spec.rb
# frozen_string_literal: true require "danger/commands/local" require "open3" RSpec.describe Danger::Local do context "prints help" do it "danger local --help flag prints help" do stdout, = Open3.capture3("danger local -h") expect(stdout).to include "Usage" end it "danger local -h prints help" do stdout, = Open3.capture3("danger local -h") expect(stdout).to include "Usage" end end describe ".options" do it "contains extra options for local command" do result = described_class.options expect(result).to include ["--use-merged-pr=[#id]", "The ID of an already merged PR inside your history to use as a reference for the local run."] expect(result).to include ["--clear-http-cache", "Clear the local http cache before running Danger locally."] expect(result).to include ["--pry", "Drop into a Pry shell after evaluating the Dangerfile."] end end context "default options" do it "pr number is nil and clear_http_cache defaults to false" do argv = CLAide::ARGV.new([]) result = described_class.new(argv) expect(result.instance_variable_get(:"@pr_num")).to eq nil expect(result.instance_variable_get(:"@clear_http_cache")).to eq false end end describe "#run" do before do allow(Danger::EnvironmentManager).to receive(:new) @dm = instance_double(Danger::Dangerfile, run: nil) allow(Danger::Dangerfile).to receive(:new).and_return @dm local_setup = instance_double(Danger::LocalSetup) allow(local_setup).to receive(:setup).and_yield allow(Danger::LocalSetup).to receive(:new).and_return local_setup end it "passes danger_id to Dangerfile and its env" do argv = CLAide::ARGV.new(["--danger_id=DANGER_ID"]) described_class.new(argv).run expect(Danger::EnvironmentManager).to have_received(:new) .with(ENV, a_kind_of(Cork::Board), "DANGER_ID") expect(@dm).to have_received(:run) .with(anything, anything, anything, "DANGER_ID", nil, nil) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/commands/init_helpers/interviewer_spec.rb
spec/lib/danger/commands/init_helpers/interviewer_spec.rb
# frozen_string_literal: true require "danger/commands/init_helpers/interviewer" RSpec.describe Danger::Interviewer do let(:cork) { double("cork") } let(:interviewer) { Danger::Interviewer.new(cork) } describe "#link" do before do allow(interviewer).to receive(:say) end it "link URL is decorated" do interviewer.link("http://danger.systems/") expect(interviewer).to have_received(:say).with(" -> \e[4mhttp://danger.systems/\e[0m\n") end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/commands/plugins/plugin_lint_spec.rb
spec/lib/danger/commands/plugins/plugin_lint_spec.rb
# frozen_string_literal: true require "danger/commands/plugins/plugin_lint" RSpec.describe Danger::PluginLint do after do Danger::Plugin.clear_external_plugins end it "runs the command" do allow(STDOUT).to receive(:puts) described_class.run(["spec/fixtures/plugins/example_fully_documented.rb"]) end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/commands/plugins/plugin_readme_spec.rb
spec/lib/danger/commands/plugins/plugin_readme_spec.rb
# frozen_string_literal: true require "danger/commands/plugins/plugin_readme" RSpec.describe Danger::PluginReadme do after do Danger::Plugin.clear_external_plugins end it "runs the command" do allow(STDOUT).to receive(:puts).with(fixture_txt("commands/plugin_md_example")) described_class.run(["spec/fixtures/plugins/example_fully_documented.rb"]) end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/commands/local_helpers/pry_setup_spec.rb
spec/lib/danger/commands/local_helpers/pry_setup_spec.rb
# frozen_string_literal: true require "danger/commands/local_helpers/pry_setup" RSpec.describe Danger::PrySetup do before { cleanup } after { cleanup } describe "#setup_pry" do it "copies the Dangerfile and appends bindings.pry" do Dir.mktmpdir do |dir| dangerfile_path = "#{dir}/Dangerfile" File.write(dangerfile_path, "") dangerfile_copy = described_class .new(testing_ui) .setup_pry(dangerfile_path, "pr") expect(File).to exist(dangerfile_copy) expect(File.read(dangerfile_copy)).to include("binding.pry; File.delete(\"_Dangerfile.tmp\")") end end it "doesn't copy a nonexistent Dangerfile" do described_class.new(testing_ui).setup_pry("", "pr") expect(File).not_to exist("_Dangerfile.tmp") end it "warns when the pry gem is not installed" do ui = testing_ui expect(Kernel).to receive(:require).with("pry").and_raise(LoadError) expect do described_class.new(ui).setup_pry("Dangerfile", "pr") end.to raise_error(SystemExit) expect(ui.err_string).to include("Pry was not found") end def cleanup File.delete "_Dangerfile.tmp" if File.exist? "_Dangerfile.tmp" end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/commands/local_helpers/local_setup_spec.rb
spec/lib/danger/commands/local_helpers/local_setup_spec.rb
# frozen_string_literal: true require "octokit" RSpec.describe Danger::LocalSetup do let(:ci_source) { FakeCiSource.new("danger/danger", "1337") } describe "#setup" do it "informs the user and runs the block" do github = double(:host => "github.com", :support_tokenless_auth= => nil, :fetch_details => nil) env = FakeEnv.new(ci_source, github) dangerfile = FakeDangerfile.new(env, false) ui = testing_ui subject = described_class.new(dangerfile, ui) subject.setup(verbose: false) { ui.puts "evaluated" } expect(ui.string).to include("Running your Dangerfile against this PR - https://github.com/danger/danger/pull/1337") expect(ui.string).to include("evaluated") end it "exits when no applicable ci source was identified" do dangerfile = FakeDangerfile.new(FakeEnv.new(nil, nil), false) ui = testing_ui subject = described_class.new(dangerfile, ui) expect do subject.setup(verbose: false) { ui.puts "evaluated" } end.to raise_error(SystemExit) expect(ui.string).to include("only works with GitHub") expect(ui.string).not_to include("evaluated") end it "turns on verbose if arguments was passed" do github = double(:host => "", :support_tokenless_auth= => nil, :fetch_details => nil) env = FakeEnv.new(ci_source, github) dangerfile = FakeDangerfile.new(env, false) ui = testing_ui subject = described_class.new(dangerfile, ui) subject.setup(verbose: true) {} expect(dangerfile.verbose).to be(true) end it "turns off verbose if arguments wasn't passed" do github = double(:host => "", :support_tokenless_auth= => nil, :fetch_details => nil) env = FakeEnv.new(ci_source, github) dangerfile = FakeDangerfile.new(env, false) ui = testing_ui subject = described_class.new(dangerfile, ui) subject.setup(verbose: false) {} expect(dangerfile.verbose).to be(false) end it "does not evaluate Dangerfile if local repo wasn't found on github" do github = double(:host => "", :support_tokenless_auth= => nil) allow(github).to receive(:fetch_details).and_raise(Octokit::NotFound.new) env = FakeEnv.new(ci_source, github) dangerfile = FakeDangerfile.new(env, false) ui = testing_ui subject = described_class.new(dangerfile, ui) subject.setup(verbose: true) { ui.puts "evaluated" } expect(ui.string).to include("was not found on GitHub") expect(ui.string).not_to include("evaluated") end end class FakeDangerfile attr_reader :env attr_accessor :verbose def initialize(env, verbose) @env = env @verbose = verbose end end class FakeEnv attr_reader :ci_source, :request_source def initialize(ci_source, request_source) @ci_source = ci_source @request_source = request_source end end class FakeCiSource attr_reader :repo_slug, :pull_request_id def initialize(repo_slug, pull_request_id) @repo_slug = repo_slug @pull_request_id = pull_request_id end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/commands/local_helpers/http_cache_spec.rb
spec/lib/danger/commands/local_helpers/http_cache_spec.rb
# frozen_string_literal: true require "danger/commands/local_helpers/http_cache" TEST_CACHE_FILE = File.join(Dir.tmpdir, "http_cache_spec") RSpec.describe Danger::HTTPCache do after do File.delete TEST_CACHE_FILE if File.exist? TEST_CACHE_FILE end it "will default to a 300 second cache expiry" do cache = described_class.new(TEST_CACHE_FILE) expect(cache.expires_in).to eq(300) end it "will allow setting a custom cache expiry" do cache = described_class.new(TEST_CACHE_FILE, expires_in: 1234) expect(cache.expires_in).to eq(1234) end it "will open a previous file by default" do store = PStore.new(TEST_CACHE_FILE) store.transaction { store["testing"] = { value: "pants", updated_at: Time.now } } result = described_class.new(TEST_CACHE_FILE).read("testing") expect(result).to eq("pants") end it "will delete a previous file if told to" do store = PStore.new(TEST_CACHE_FILE) store.transaction { store["testing"] = "pants" } result = described_class.new(TEST_CACHE_FILE, clear_cache: true).read("testing") expect(result).to be_nil end it "will honor the TTL when a read attempt is made" do now = Time.now.to_i store = PStore.new(TEST_CACHE_FILE) store.transaction do store["testing_valid_ttl"] = { value: "pants", updated_at: now - 280 } store["testing_invalid_ttl"] = { value: "pants", updated_at: now - 301 } end cache = described_class.new(TEST_CACHE_FILE) expect(cache.read("testing_valid_ttl")).to eq("pants") expect(cache.read("testing_invalid_ttl")).to be_nil end it "will delete a key" do cache = described_class.new(TEST_CACHE_FILE) cache.write("testing_delete", "pants") cache.delete("testing_delete") expect(cache.read("testing_delete")).to be_nil end it "will write a key and timestamp" do cache = described_class.new(TEST_CACHE_FILE) cache.write("testing_write", "pants") store = PStore.new(TEST_CACHE_FILE) store.transaction do expect(store["testing_write"]).to_not be_nil expect(store["testing_write"][:value]).to eq("pants") expect(store["testing_write"][:updated_at]).to be_within(1).of(Time.now.to_i) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/core_ext/string_spec.rb
spec/lib/danger/core_ext/string_spec.rb
# frozen_string_literal: true RSpec.describe String do describe "#danger_pluralize" do examples = [ { count: 0, string: "0 errors" }, { count: 1, string: "1 error" }, { count: 2, string: "2 errors" } ] examples.each do |example| it "returns '#{example[:string]}' when count = #{example[:count]}" do expect("error".danger_pluralize(example[:count])).to eq(example[:string]) end end end describe "#danger_underscore" do it "converts properly" do expect("ExampleClass".danger_underscore).to eq("example_class") end end describe "#danger_truncate" do it "truncates strings exceeding the limit" do expect("super long string".danger_truncate(5)).to eq("super...") end it "does not truncate strings that are on the limit" do expect("12345".danger_truncate(5)).to eq("12345") end it "does not truncate strings that are within the limit" do expect("123".danger_truncate(5)).to eq("123") end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/core_ext/file_list_spec.rb
spec/lib/danger/core_ext/file_list_spec.rb
# frozen_string_literal: true require "danger/core_ext/file_list" RSpec.describe Danger::FileList do describe "#include?" do before do paths = ["path1/file_name.txt", "path1/file_name1.txt", "path2/subfolder/example.json", "path1/file_name_with_[brackets].txt"] @filelist = Danger::FileList.new(paths) end it "supports exact matches" do expect(@filelist.include?("path1/file_name.txt")).to eq(true) expect(@filelist.include?("path1/file_name_with_[brackets].txt")).to eq(true) end it "supports * for wildcards" do expect(@filelist.include?("path1/*.txt")).to eq(true) end it "supports ? for single chars" do expect(@filelist.include?("path1/file_name.???")).to eq(true) expect(@filelist.include?("path1/file_name.?")).to eq(false) end it "returns false if nothing was found" do expect(@filelist.include?("notFound")).to eq(false) end it "returns false if file path is nil" do @filelist = Danger::FileList.new([nil]) expect(@filelist.include?("pattern")).to eq(false) end it "supports {a,b} as union of multiple patterns" do expect(@filelist.include?("{path1/file_name.txt,path3/file_name.rb}")).to eq(true) expect(@filelist.include?("{path1/file_name.rb,path1/file_name.js}")).to eq(false) expect(@filelist.include?("{path1/file_name.rb,path1/file_name.js,path2/*}")).to eq(true) end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/plugin_support/plugin_linter_spec.rb
spec/lib/danger/plugin_support/plugin_linter_spec.rb
# frozen_string_literal: true require "danger/plugin_support/plugin_parser" require "danger/plugin_support/plugin_linter" def json_doc_for_path(path) parser = Danger::PluginParser.new path parser.parse parser.to_json end RSpec.describe Danger::PluginParser do it "creates a set of errors for fixtured plugins" do json = json_doc_for_path("spec/fixtures/plugins/plugin_many_methods.rb") linter = Danger::PluginLinter.new(json) linter.lint titles = ["Description Markdown", "Examples", "Description", "Description"] expect(linter.errors.map(&:title)).to eq(titles) end it "creates a set of warnings for fixtured plugins" do json = json_doc_for_path("spec/fixtures/plugins/plugin_many_methods.rb") linter = Danger::PluginLinter.new(json) linter.lint titles = ["Tags", "References", "Return Type", "Return Type", "Return Type", "Unknown Param", "Return Type"] expect(linter.warnings.map(&:title)).to eq(titles) end it "fails when there are errors" do linter = Danger::PluginLinter.new({}) expect(linter.failed?).to eq(false) linter.warnings = [1, 2, 3] expect(linter.failed?).to eq(false) linter.errors = [1, 2, 3] expect(linter.failed?).to eq(true) end it "handles outputting a warning" do ui = testing_ui linter = Danger::PluginLinter.new({}) warning = Danger::PluginLinter::Rule.new(:warning, 30, "Example Title", "Example Description", nil) warning.metadata = { name: "NameOfExample" } warning.type = "TypeOfThing" linter.warnings << warning linter.print_summary(ui) expect(ui.string).to eq("\n[!] Passed\n\nWarnings\n - Example Title - NameOfExample (TypeOfThing):\n - Example Description\n - @see - https://github.com/dbgrandi/danger-prose/blob/v2.0.0/lib/danger_plugin.rb#L30\n\n") end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/plugin_support/plugin_file_resolver_spec.rb
spec/lib/danger/plugin_support/plugin_file_resolver_spec.rb
# frozen_string_literal: true require "lib/danger/plugin_support/plugin_file_resolver" RSpec.describe Danger::PluginFileResolver do describe "#resolve" do context "Given list of gems" do it "resolves for gems" do resolver = Danger::PluginFileResolver.new(["danger", "rails"]) expect(Danger::GemsResolver).to receive_message_chain(:new, :call) resolver.resolve end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/plugin_support/plugin_spec.rb
spec/lib/danger/plugin_support/plugin_spec.rb
# frozen_string_literal: true RSpec.describe Danger::Plugin do it "creates an instance name based on the class name" do class DangerTestClassNamePlugin < Danger::Plugin; end expect(DangerTestClassNamePlugin.instance_name).to eq("test_class_name_plugin") end it "should forward unknown method calls to the dangerfile" do class DangerTestForwardPlugin < Danger::Plugin; end class DangerFileMock attr_accessor :pants def check(*args, **kargs); end end plugin = DangerTestForwardPlugin.new(DangerFileMock.new) expect do plugin.pants end.to_not raise_error expect do plugin.check("a", "b", verbose: true) end.to_not raise_error end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/plugin_support/gems_resolver_spec.rb
spec/lib/danger/plugin_support/gems_resolver_spec.rb
# frozen_string_literal: true require "lib/danger/plugin_support/gems_resolver" RSpec.describe Danger::GemsResolver do def expected_path(dir) [ "#{dir}/vendor/gems/ruby/2.3.0/gems/danger-rubocop-0.3.0/lib/danger_plugin.rb", "#{dir}/vendor/gems/ruby/2.3.0/gems/danger-rubocop-0.3.0/lib/version.rb" ] end def expected_gems [ { name: "danger-rubocop", gem: "danger-rubocop", author: ["Ash Furrow"], url: "https://github.com/ashfurrow/danger-rubocop", description: "A Danger plugin for running Ruby files through Rubocop.", license: "MIT", version: "0.3.0" } ] end # Mimic bundle install --path vendor/gems when install danger-rubocop def fake_bundle_install_path_vendor_gems_in(spec_root) FileUtils.mkdir_p("vendor/gems/ruby/2.3.0/gems/danger-rubocop-0.3.0/lib") FileUtils.touch("vendor/gems/ruby/2.3.0/gems/danger-rubocop-0.3.0/lib/version.rb") FileUtils.touch("vendor/gems/ruby/2.3.0/gems/danger-rubocop-0.3.0/lib/danger_plugin.rb") FileUtils.mkdir_p("vendor/gems/ruby/2.3.0/specifications") FileUtils.cp( "#{spec_root}/spec/fixtures/gemspecs/danger-rubocop.gemspec", "vendor/gems/ruby/2.3.0/specifications/danger-rubocop-0.3.0.gemspec" ) end describe "#call" do it "create gemfile, bundle, and returns" do spec_root = Dir.pwd gem_names = ["danger-rubocop"] tmpdir = Dir.mktmpdir # We want to control the temp dir created in gems_resolver # to compare in our test allow(Dir).to receive(:mktmpdir) { tmpdir } Dir.chdir(tmpdir) do expect(Bundler).to receive(:with_clean_env) do fake_bundle_install_path_vendor_gems_in(spec_root) end resolver = described_class.new(gem_names) resolver.call result = resolver.send(:all_gems_metadata) expect(result).to be_a Array expect(result.first).to match_array expected_path(tmpdir) expect(result.last).to match_array expected_gems end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/plugin_support/plugin_parser_spec.rb
spec/lib/danger/plugin_support/plugin_parser_spec.rb
# frozen_string_literal: true require "danger/plugin_support/plugin_parser" RSpec.describe Danger::PluginParser do it "includes an example plugin" do parser = described_class.new "spec/fixtures/plugins/example_broken.rb" parser.parse plugin_docs = parser.registry.at("Danger::Dangerfile::ExampleBroken") expect(plugin_docs).to be_truthy end it "finds classes from inside the file" do parser = described_class.new "spec/fixtures/plugins/example_broken.rb" parser.parse classes = parser.classes_in_file class_syms = classes.map(&:name) expect(class_syms).to eq %i(Dangerfile ExampleBroken) end it "skips non-subclasses of Danger::Plugin" do parser = described_class.new "spec/fixtures/plugins/example_broken.rb" parser.parse plugins = parser.plugins_from_classes(parser.classes_in_file) class_syms = plugins.map(&:name) expect(class_syms).to eq [] end it "find subclasses of Danger::Plugin" do parser = described_class.new "spec/fixtures/plugins/example_remote.rb" parser.parse plugins = parser.plugins_from_classes(parser.classes_in_file) class_syms = plugins.map(&:name) expect(class_syms).to eq [:ExampleRemote] end it "outputs JSON for badly documented subclasses of Danger::Plugin" do parser = described_class.new "spec/fixtures/plugins/example_remote.rb" parser.parse plugins = parser.plugins_from_classes(parser.classes_in_file) json = parser.to_h(plugins) sanitized_json = JSON.pretty_generate(json).gsub(Dir.pwd, "") fixture = "spec/fixtures/plugin_json/example_remote.json" # File.write(fixture, sanitized_json) # Skipping this test for windows, pathing gets complex, and no-one # is generating gem docs on windows. if Gem.win_platform? expect(1).to eq(1) else expect(JSON.parse(sanitized_json)).to eq JSON.load_file(fixture) end end it "outputs JSON for well documented subclasses of Danger::Plugin" do parser = described_class.new "spec/fixtures/plugins/example_fully_documented.rb" parser.parse plugins = parser.plugins_from_classes(parser.classes_in_file) json = parser.to_h(plugins) sanitized_json = JSON.pretty_generate(json).gsub(Dir.pwd, "") fixture = "spec/fixtures/plugin_json/example_fully_doc.json" # File.write(fixture, sanitized_json) # Skipping this test for windows, pathing gets complex, and no-one # is generating gem docs on windows. if Gem.win_platform? expect(1).to eq(1) else expect(JSON.parse(sanitized_json)).to eq JSON.load_file(fixture) end end it "creates method descriptions that make sense" do parser = described_class.new "spec/fixtures/plugins/plugin_many_methods.rb" parser.parse plugins = parser.plugins_from_classes(parser.classes_in_file) json = parser.to_h(plugins) method_one_liners = json.first[:methods].map { |m| m[:one_liner] } expect(method_one_liners).to eq([ "one", "two", "two_point_five", "three(param1=nil: String)", "four(param1=nil: Number, param2: String) -> String", "five(param1=[]: Array<String>, param2: Filepath, param3: Unknown) -> String", "six? -> Bool" ]) end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/plugins/dangerfile_bitbucket_cloud_plugin_spec.rb
spec/lib/danger/plugins/dangerfile_bitbucket_cloud_plugin_spec.rb
# frozen_string_literal: true RSpec.describe Danger::DangerfileBitbucketCloudPlugin, host: :bitbucket_cloud do let(:dangerfile) { testing_dangerfile } let(:plugin) { described_class.new(dangerfile) } before do stub_pull_request end describe "plugin" do before do dangerfile.env.request_source.fetch_details end describe "#pr_json" do it "has a non empty json" do expect(plugin.pr_json).to be_truthy end end describe "#pr_title" do it "has a fetched title" do expect(plugin.pr_title).to eq("This is a danger test for bitbucket cloud") end end describe "#pr_author" do it "has a fetched author" do expect(plugin.pr_author).to eq("AName") end end describe "#pr_link" do it "has a fetched link to it self" do expect(plugin.pr_link).to eq("https://api.bitbucket.org/2.0/repositories/ios/fancyapp/pullrequests/2080") end end describe "#branch_for_base" do it "has a fetched branch for base" do expect(plugin.branch_for_base).to eq("develop") end end describe "#branch_for_head" do it "has a fetched branch for head" do expect(plugin.branch_for_head).to eq("feature/test_danger") end end describe "#base_commit" do it "has a fetched base commit" do expect(plugin.base_commit).to eq("9c823062cf99") end end describe "#head_commit" do it "has a fetched head commit" do expect(plugin.head_commit).to eq("b6f5656b6ac9") end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/plugins/dangerfile_bitbucket_server_plugin_spec.rb
spec/lib/danger/plugins/dangerfile_bitbucket_server_plugin_spec.rb
# frozen_string_literal: true RSpec.describe Danger::DangerfileBitbucketServerPlugin, host: :bitbucket_server do let(:dangerfile) { testing_dangerfile } let(:plugin) { described_class.new(dangerfile) } before do stub_pull_request end describe "plugin" do before do dangerfile.env.request_source.fetch_details end describe "#pr_json" do it "has a non empty json" do expect(plugin.pr_json).to be_truthy end end describe "#pr_title" do it "has a fetched title" do expect(plugin.pr_title).to eq("This is a danger test") end end describe "#pr_author" do it "has a fetched author" do expect(plugin.pr_author).to eq("a.user") end end describe "#pr_link" do it "has a fetched link to it self" do expect(plugin.pr_link).to eq("https://stash.example.com/projects/IOS/repos/fancyapp/pull-requests/2080") end end describe "#branch_for_base" do it "has a fetched branch for base" do expect(plugin.branch_for_base).to eq("develop") end end describe "#branch_for_head" do it "has a fetched branch for head" do expect(plugin.branch_for_head).to eq("feature/Danger") end end describe "#base_commit" do it "has a fetched base commit" do expect(plugin.base_commit).to eq("b366c9564ad57786f0e5c6b8333c7aa1e2e90b9a") end end describe "#head_commit" do it "has a fetched head commit" do expect(plugin.head_commit).to eq("c50b3f61e90dac6a00b7d0c92e415a4348bb280a") end end describe "#html_link" do it "creates a usable html link" do skip "Atlassian disabled inline HTML support for Bitbucket Server" expect(plugin.html_link("Classes/Main Categories/Feed/FeedViewController.m")).to include( "<a href='https://stash.example.com/projects/IOS/repos/fancyapp/browse/Classes/Main%20Categories/Feed/FeedViewController.m?at=c50b3f61e90dac6a00b7d0c92e415a4348bb280a'>Classes/Main Categories/Feed/FeedViewController.m</a>" ) end it "handles #XX line numbers in the same format a the other plugins" do skip "Atlassian disabled inline HTML support for Bitbucket Server" expect(plugin.html_link("Classes/Main Categories/Feed/FeedViewController.m#100")).to include( "<a href='https://stash.example.com/projects/IOS/repos/fancyapp/browse/Classes/Main%20Categories/Feed/FeedViewController.m?at=c50b3f61e90dac6a00b7d0c92e415a4348bb280a#100'>Classes/Main Categories/Feed/FeedViewController.m</a>" ) end end describe "#markdown_link" do it "creates a usable markdown link" do expect(plugin.markdown_link("Classes/Main Categories/Feed/FeedViewController.m")).to include( "[Classes/Main Categories/Feed/FeedViewController.m](https://stash.example.com/projects/IOS/repos/fancyapp/browse/Classes/Main%20Categories/Feed/FeedViewController.m?at=c50b3f61e90dac6a00b7d0c92e415a4348bb280a)" ) end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/danger_core/standard_error_spec.rb
spec/lib/danger/danger_core/standard_error_spec.rb
# frozen_string_literal: true RSpec.describe Danger::DSLError do let(:file_path) do Pathname.new(File.join("spec", "fixtures", "dangerfile_with_error")) end let(:description) do "Invalid `#{file_path.basename}` file: undefined local "\ "variable or method `abc' for #<Danger::Dangerfile:1>" end let(:backtrace) do [ "#{File.join('fake', 'path', 'dangerfile.rb')}:68:in `method_missing", "#{File.join('spec', 'fixtures', 'dangerfile_with_error')}:2:in `block in parse'", "#{File.join('fake', 'path', 'dangerfile.rb')}:199:in `eval" ] end subject { Danger::DSLError.new(description, file_path, backtrace) } describe "#message" do context "when danger version outdated" do before { allow(Danger).to receive(:danger_outdated?).and_return(0) } it "returns colored description with Dangerfile trace" do description = "[!] Invalid `dangerfile_with_error` file: undefined "\ "local variable or method `abc' for #<Danger::Dangerfile:1>"\ ". Updating the Danger gem might fix the issue. "\ "Your Danger version: #{Danger::VERSION}, "\ "latest Danger version: 0" expectation = [ "\e[31m", description, "\e[0m", " # from spec/fixtures/dangerfile_with_error:2", " # -------------------------------------------", " # # This will fail", " > abc", " # -------------------------------------------" ] expect(subject.message.split("\n")).to eq expectation end end context "when danger version latest" do before { allow(Danger).to receive(:danger_outdated?).and_return(false) } it "returns colored description with Dangerfile trace" do description = "[!] Invalid `dangerfile_with_error` file: undefined " \ "local variable or method `abc' for #<Danger::Dangerfile:1>\e[0m" expectation = [ "\e[31m", description, " # from spec/fixtures/dangerfile_with_error:2", " # -------------------------------------------", " # # This will fail", " > abc", " # -------------------------------------------" ] expect(subject.message.split("\n")).to eq expectation end end end describe "#to_markdown" do context "when danger version outdated" do before { allow(Danger).to receive(:danger_outdated?).and_return(0) } it "returns description with Dangerfile trace as a escaped markdown" do description = "[!] Invalid `dangerfile_with_error` file: undefined " \ "local variable or method `abc` for #\\<Danger::Dangerfile:1\\>" \ ". Updating the Danger gem might fix the issue. "\ "Your Danger version: #{Danger::VERSION}, "\ "latest Danger version: 0" expectation = [ "## Danger has errored", description, "", "```", " # from spec/fixtures/dangerfile_with_error:2", " # -------------------------------------------", " # # This will fail", " > abc", " # -------------------------------------------", "```" ] subject.to_markdown.message.split("\n").each_with_index do |chunk, index| expect(chunk).to eq expectation[index] end expect(subject.to_markdown.message.split("\n")).to eq expectation end end context "when danger version latest" do before { allow(Danger).to receive(:danger_outdated?).and_return(false) } it "returns description with Dangerfile trace as a escaped markdown" do description = "[!] Invalid `dangerfile_with_error` file: undefined " \ "local variable or method `abc` for #\\<Danger::Dangerfile:1\\>" expectation = [ "## Danger has errored", description, "```", " # from spec/fixtures/dangerfile_with_error:2", " # -------------------------------------------", " # # This will fail", " > abc", " # -------------------------------------------", "```" ] expect(subject.to_markdown.message.split("\n")).to eq expectation end end end after { allow(Danger).to receive(:danger_outdated?).and_call_original } end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/danger_core/message_group_spec.rb
spec/lib/danger/danger_core/message_group_spec.rb
# frozen_string_literal: true require "danger/danger_core/messages/violation" require "danger/danger_core/message_group" RSpec.describe Danger::MessageGroup do subject(:message_group) { described_class.new(file: file, line: line) } shared_examples_for "with varying line and file" do |behaves_like:| context "with nil file and line" do let(:file) { nil } let(:line) { nil } it_behaves_like behaves_like end context "with a filename and nil line" do let(:file) { "test.txt" } let(:line) { nil } it_behaves_like behaves_like end context "with a line and nil filename" do let(:file) { nil } let(:line) { 180 } it_behaves_like behaves_like end context "with a file and line" do let(:file) { "test.txt" } let(:line) { 190 } it_behaves_like behaves_like end end describe "#same_line?" do subject { message_group.same_line? other } shared_examples_for "true when same line" do context "on the same line" do let(:other_file) { file } let(:other_line) { line } it { is_expected.to be true } end context "on a different line" do let(:other_file) { file } let(:other_line) { 200 } it { is_expected.to be false } end context "in a different file" do let(:other_file) { "jeff.txt" } let(:other_line) { line } it { is_expected.to be false } end context "in a different on a different line" do let(:other_file) { "jeff.txt" } let(:other_line) { 200 } it { is_expected.to be false } end end context "when other is a Violation" do let(:other) do Danger::Violation.new("test message", false, other_file, other_line) end include_examples "with varying line and file", behaves_like: "true when same line" end context "when other is a Markdown" do let(:other) do Danger::Markdown.new("test message", other_file, other_line) end include_examples "with varying line and file", behaves_like: "true when same line" end context "when other is a MessageGroup" do let(:other) do described_class.new(file: other_file, line: other_line) end include_examples "with varying line and file", behaves_like: "true when same line" end end describe "<<" do subject { message_group << message } shared_examples_for "adds when same line" do context "on the same line" do let(:other_file) { file } let(:other_line) { line } it { expect { subject }.to change { message_group.messages.count }.by 1 } end context "on a different line" do let(:other_file) { file } let(:other_line) { 200 } it { expect { subject }.not_to(change { message_group.messages.count }) } end context "in a different file" do let(:other_file) { "jeff.txt" } let(:other_line) { line } it { expect { subject }.not_to(change { message_group.messages.count }) } end context "in a different file on a different line" do let(:other_file) { "jeff.txt" } let(:other_line) { 200 } it { expect { subject }.not_to(change { message_group.messages.count }) } end end context "when message is a Violation" do let(:message) do Danger::Violation.new("test message", false, other_file, other_line) end include_examples "with varying line and file", behaves_like: "adds when same line" end context "when message is a Markdown" do let(:message) do Danger::Markdown.new("test message", other_file, other_line) end include_examples "with varying line and file", behaves_like: "adds when same line" end end describe "#stats" do subject { message_group.stats } let(:file) { nil } let(:line) { nil } before do warnings.each { |w| message_group << w } errors.each { |e| message_group << e } end let(:warnings) { [] } let(:errors) { [] } context "when group has no warnings" do context "when group has no errors" do it { is_expected.to eq(warnings_count: 0, errors_count: 0) } end context "when group has one error" do let(:errors) { [Danger::Violation.new("test", false, file, line, type: :error)] } it { is_expected.to eq(warnings_count: 0, errors_count: 1) } end context "when group has 10 errors" do let(:errors) { [Danger::Violation.new("test", false, file, line, type: :error)] * 10 } it { is_expected.to eq(warnings_count: 0, errors_count: 10) } end end context "when group has one warning" do let(:warnings) { [Danger::Violation.new("test", false, file, line, type: :warning)] } context "when group has no errors" do it { is_expected.to eq(warnings_count: 1, errors_count: 0) } end context "when group has one error" do let(:errors) { [Danger::Violation.new("test", false, file, line, type: :error)] } it { is_expected.to eq(warnings_count: 1, errors_count: 1) } end context "when group has 10 errors" do let(:errors) { [Danger::Violation.new("test", false, file, line, type: :error)] * 10 } it { is_expected.to eq(warnings_count: 1, errors_count: 10) } end end context "when group has 10 warnings" do let(:warnings) { [Danger::Violation.new("test", false, file, line, type: :warning)] * 10 } context "when group has no errors" do it { is_expected.to eq(warnings_count: 10, errors_count: 0) } end context "when group has one error" do let(:errors) { [Danger::Violation.new("test", false, file, line, type: :error)] } it { is_expected.to eq(warnings_count: 10, errors_count: 1) } end context "when group has 10 errors" do let(:errors) { [Danger::Violation.new("test", false, file, line, type: :error)] * 10 } it { is_expected.to eq(warnings_count: 10, errors_count: 10) } end end end describe "#markdowns" do subject { message_group.markdowns } let(:file) { nil } let(:line) { nil } before do messages.each { |m| message_group << m } markdowns.each { |m| message_group << m } end let(:markdowns) { [] } let(:messages) { [] } context "with no markdowns" do it { is_expected.to eq [] } end context "with 2 markdowns" do let(:markdowns) { [Danger::Markdown.new("hello"), Danger::Markdown.new("hi")] } context "with no other messages" do it "has both markdowns" do expect(Set.new(subject)).to eq Set.new(markdowns) end end context "with other messages" do let(:messages) { [Danger::Violation.new("warning!", false, type: :warning), Danger::Violation.new("error!", false, type: :error)] } it "still only has both markdowns" do expect(Set.new(subject)).to eq Set.new(markdowns) end end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/danger_core/environment_manager_spec.rb
spec/lib/danger/danger_core/environment_manager_spec.rb
# frozen_string_literal: true require "danger/danger_core/environment_manager" RSpec.describe Danger::EnvironmentManager, use: :ci_helper do describe ".local_ci_source" do it "loads Appcircle" do with_appcircle_setup_and_is_a_pull_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::Appcircle end end it "loads Bamboo" do with_bamboo_setup_and_is_a_pull_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::Bamboo end end it "loads Bitrise" do with_bitrise_setup_and_is_a_pull_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::Bitrise end end it "loads Buildkite" do with_buildkite_setup_and_is_a_pull_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::Buildkite end end it "loads Circle" do with_circle_setup_and_is_a_pull_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::CircleCI end end it "loads Codemagic" do with_codemagic_setup_and_is_a_pull_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::Codemagic end end it "loads Drone" do with_drone_setup_and_is_a_pull_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::Drone end end it "loads GitLab CI" do with_gitlabci_setup_and_is_a_merge_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::GitLabCI end end it "loads Jenkins (Github)" do with_jenkins_setup_github_and_is_a_pull_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::Jenkins end end it "loads Jenkins (Gitlab)" do with_jenkins_setup_gitlab_and_is_a_merge_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::Jenkins end end it "loads Jenkins (Gitlab v3)" do with_jenkins_setup_gitlab_v3_and_is_a_merge_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::Jenkins end end it "loads Local Git Repo" do with_localgitrepo_setup do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::LocalGitRepo end end it "loads Screwdriver" do with_screwdriver_setup_and_is_a_pull_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::Screwdriver end end it "loads Semaphore" do with_semaphore_setup_and_is_a_pull_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::Semaphore end end it "loads Surf" do with_surf_setup_and_is_a_pull_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::Surf end end it "loads TeamCity" do with_teamcity_setup_github_and_is_a_pull_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::TeamCity end end it "loads Travis" do with_travis_setup_and_is_a_pull_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::Travis end end it "loads Xcode Server" do with_xcodeserver_setup_and_is_a_pull_request do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::XcodeServer end end it "does not return a CI source with no ENV deets" do we_dont_have_ci_setup do |system_env| expect(Danger::EnvironmentManager.local_ci_source(system_env)).to eq nil end end context "when Local Only Git Repo is valid" do it "loads Local Only Git Repo" do with_localonlygitrepo_setup do |system_env| expect(described_class.local_ci_source(system_env)).to eq Danger::LocalOnlyGitRepo end end it "loads Local Only Git Repo ignoring other valid sources" do with_bitrise_setup_and_is_a_pull_request do |system_env_bitrise| with_localonlygitrepo_setup do |system_env_local_only| system_env = system_env_bitrise.merge(system_env_local_only) expect(described_class.local_ci_source(system_env)).to eq Danger::LocalOnlyGitRepo end end end end end describe ".pr?" do it "loads Appcircle" do with_appcircle_setup_and_is_a_pull_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads Bamboo" do with_bamboo_setup_and_is_a_pull_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads Bitrise" do with_bitrise_setup_and_is_a_pull_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads Buildkite" do with_buildkite_setup_and_is_a_pull_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads Circle" do with_circle_setup_and_is_a_pull_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads Codemagic" do with_codemagic_setup_and_is_a_pull_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads Drone" do with_drone_setup_and_is_a_pull_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads GitLab CI" do with_gitlabci_setup_and_is_a_merge_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads Jenkins (Github)" do with_jenkins_setup_github_and_is_a_pull_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads Jenkins (Gitlab)" do with_jenkins_setup_gitlab_and_is_a_merge_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads Jenkins (Gitlab v3)" do with_jenkins_setup_gitlab_v3_and_is_a_merge_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads Local Git Repo" do with_localgitrepo_setup do |system_env| expect(described_class.pr?(system_env)).to eq(false) end end it "loads Screwdriver" do with_screwdriver_setup_and_is_a_pull_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads Semaphore" do with_semaphore_setup_and_is_a_pull_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads Surf" do with_surf_setup_and_is_a_pull_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads TeamCity" do with_teamcity_setup_github_and_is_a_pull_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads Travis" do with_travis_setup_and_is_a_pull_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "loads Xcode Server" do with_xcodeserver_setup_and_is_a_pull_request do |system_env| expect(described_class.pr?(system_env)).to eq(true) end end it "does not return a CI source with no ENV deets" do env = { "KEY" => "VALUE" } expect(Danger::EnvironmentManager.local_ci_source(env)).to eq nil end end describe ".danger_head_branch" do it "returns danger_head" do expect(described_class.danger_head_branch).to eq("danger_head") end end describe ".danger_base_branch" do it "returns danger_base" do expect(described_class.danger_base_branch).to eq("danger_base") end end describe "#pr?" do it "returns true if has a ci source" do with_travis_setup_and_is_a_pull_request(request_source: :github) do |env| env_manager = Danger::EnvironmentManager.new(env, testing_ui) expect(env_manager.pr?).to eq true end end end describe "#danger_id" do it "returns the default identifier when none is provided" do with_travis_setup_and_is_a_pull_request(request_source: :github) do |env| env_manager = Danger::EnvironmentManager.new(env, testing_ui) expect(env_manager.danger_id).to eq("danger") end end it "returns the identifier user by danger" do with_travis_setup_and_is_a_pull_request(request_source: :github) do |env| env_manager = Danger::EnvironmentManager.new(env, testing_ui, "test_identifier") expect(env_manager.danger_id).to eq("test_identifier") end end end def git_repo_with_danger_branches_setup Dir.mktmpdir do |dir| Dir.chdir dir do `git init -b master` `git remote add origin git@github.com:devdanger/devdanger.git` `touch README.md` `git add .` `git commit -q --no-gpg-sign -m "Initial Commit"` `git checkout -q -b danger_head` `git commit -q --no-gpg-sign --allow-empty -m "HEAD"` head_sha = `git rev-parse HEAD`.chomp![0..6] `git checkout -q master` `git checkout -q -b danger_base` `git commit -q --no-gpg-sign --allow-empty -m "BASE"` base_sha = `git rev-parse HEAD`.chomp![0..6] `git checkout -q master` yield(head_sha, base_sha) end end end describe "#clean_up" do it "delete danger branches" do git_repo_with_danger_branches_setup do |_, _| with_travis_setup_and_is_a_pull_request(request_source: :github) do |system_env| described_class.new(system_env, testing_ui).clean_up branches = `git branch`.lines.map(&:strip!) expect(branches).not_to include("danger_head") expect(branches).not_to include("danger_base") end end end end describe "#meta_info_for_head" do it "returns last commit of danger head branch" do git_repo_with_danger_branches_setup do |head_sha, _base_sha| with_travis_setup_and_is_a_pull_request(request_source: :github) do |env| result = described_class.new(env, testing_ui).meta_info_for_head expect(result).to include(head_sha) end end end end describe "#meta_info_for_base" do it "returns last commit of danger base branch" do git_repo_with_danger_branches_setup do |_head_sha, base_sha| with_travis_setup_and_is_a_pull_request(request_source: :github) do |env| result = described_class.new(env, testing_ui).meta_info_for_base expect(result).to include(base_sha) end end end end it "stores travis in the source" do number = 123 env = { "DANGER_GITHUB_API_TOKEN" => "abc123", "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true", "TRAVIS_REPO_SLUG" => "KrauseFx/fastlane", "TRAVIS_PULL_REQUEST" => number.to_s } danger_em = Danger::EnvironmentManager.new(env, testing_ui) expect(danger_em.ci_source.pull_request_id).to eq(number.to_s) end it "stores circle in the source" do number = 800 env = { "DANGER_GITHUB_API_TOKEN" => "abc123", "CIRCLE_BUILD_NUM" => "true", "CI_PULL_REQUEST" => "https://github.com/artsy/eigen/pull/#{number}", "CIRCLE_PROJECT_USERNAME" => "orta", "CIRCLE_PROJECT_REPONAME" => "thing" } danger_em = Danger::EnvironmentManager.new(env, testing_ui) expect(danger_em.ci_source.pull_request_id).to eq(number.to_s) end it "creates a GitHub attr" do env = { "DANGER_GITHUB_API_TOKEN" => "abc123", "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true", "TRAVIS_REPO_SLUG" => "KrauseFx/fastlane", "TRAVIS_PULL_REQUEST" => 123.to_s } danger_em = Danger::EnvironmentManager.new(env, testing_ui) expect(danger_em.request_source).to be_truthy end it "skips push runs and only runs for pull requests" do env = { "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true" } expect(Danger::EnvironmentManager.local_ci_source(env)).to be_truthy expect(Danger::EnvironmentManager.pr?(env)).to eq(false) end it "uses local git repo and github when running locally" do env = { "DANGER_USE_LOCAL_GIT" => "true" } danger_em = Danger::EnvironmentManager.new(env, testing_ui) expect(danger_em.ci_source).to be_truthy expect(danger_em.request_source).to be_truthy end context "Without API tokens" do it "handles providing useful github info when the repo url is github" do req_src_env = { "DANGER_GITHUB_API_TOKEN" => "hi", "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true" } ui = testing_ui danger_em = Danger::EnvironmentManager.new(req_src_env, ui) expect do danger_em.raise_error_for_no_request_source(req_src_env, ui) end.to raise_error(SystemExit) expect(ui.string).to include("For your GitHub repo, you need to expose: DANGER_GITHUB_API_TOKEN") expect(ui.string).to include("You may also need: DANGER_GITHUB_HOST, DANGER_GITHUB_API_BASE_URL") end it "handles providing useful gitlab info when the repo url is gitlab" do req_src_env = { "DANGER_GITHUB_API_TOKEN" => "hi", "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true" } ui = testing_ui danger_em = Danger::EnvironmentManager.new(req_src_env, ui) danger_em.ci_source.repo_url = "https://gitlab.com/danger-systems/danger.systems" expect do danger_em.raise_error_for_no_request_source(req_src_env, ui) end.to raise_error(SystemExit) expect(ui.string).to include("For your GitLab repo, you need to expose: DANGER_GITLAB_API_TOKEN") end it "handles providing useful bitbucket info when the repo url is bitbuckety" do req_src_env = { "DANGER_GITHUB_API_TOKEN" => "hi", "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true" } ui = testing_ui danger_em = Danger::EnvironmentManager.new(req_src_env, ui) danger_em.ci_source.repo_url = "https://bitbucket.org/ios/fancyapp" expect do danger_em.raise_error_for_no_request_source(req_src_env, ui) end.to raise_error(SystemExit) expect(ui.string).to include("For your BitbucketCloud repo, you need to expose: DANGER_BITBUCKETCLOUD_UUID") end it "handles throwing out all kinds of info when the repo url isnt recognised" do req_src_env = { "DANGER_GITHUB_API_TOKEN" => "hi", "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true" } ui = testing_ui danger_em = Danger::EnvironmentManager.new(req_src_env, ui) danger_em.ci_source.repo_url = "https://orta.io/my/thing" expect do danger_em.raise_error_for_no_request_source(req_src_env, ui) end.to raise_error(SystemExit) messages = [ "For Danger to run on this project, you need to expose a set of following the ENV vars:", " - GitHub: DANGER_GITHUB_API_TOKEN", " - GitLab: DANGER_GITLAB_API_TOKEN", " - BitbucketServer: DANGER_BITBUCKETSERVER_USERNAME, DANGER_BITBUCKETSERVER_PASSWORD, DANGER_BITBUCKETSERVER_HOST", " - BitbucketCloud: DANGER_BITBUCKETCLOUD_UUID" ] messages.each do |m| expect(ui.string).to include(m) end end it "includes all your env var keys" do req_src_env = { "DANGER_GITHUB_API_TOKEN" => "hi", "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true", "RANDO_KEY" => "secret" } ui = testing_ui danger_em = Danger::EnvironmentManager.new(req_src_env, ui) danger_em.ci_source.repo_url = "https://orta.io/my/thing" expect do danger_em.raise_error_for_no_request_source(req_src_env, ui) end.to raise_error(SystemExit) expect(ui.string).to include("Found these keys in your ENV: DANGER_GITHUB_API_TOKEN, HAS_JOSH_K_SEAL_OF_APPROVAL, RANDO_KEY.") end it "prints travis note in subtitle" do req_src_env = { "DANGER_GITHUB_API_TOKEN" => "hi", "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true", "RANDO_KEY" => "secret", "TRAVIS_SECURE_ENV_VARS" => "true" } ui = testing_ui danger_em = Danger::EnvironmentManager.new(req_src_env, ui) danger_em.ci_source.repo_url = "https://orta.io/my/thing" expect do danger_em.raise_error_for_no_request_source(req_src_env, ui) end.to raise_error(SystemExit) expect(ui.string).to include("Travis note: If you have an open source project, you should ensure 'Display value in build log' enabled for these flags, so that PRs from forks work.") end context "cannot find request source" do it "raises error" do env = { "DANGER_USE_LOCAL_GIT" => "true" } fake_ui = double("Cork::Board") allow(Cork::Board).to receive(:new) { fake_ui } allow(Danger::RequestSources::RequestSource).to receive(:available_request_sources) { [] } expect(fake_ui).to receive(:title) expect(fake_ui).to receive(:puts).exactly(5).times expect { Danger::EnvironmentManager.new(env, nil) }.to raise_error(SystemExit) end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/danger_core/executor_spec.rb
spec/lib/danger/danger_core/executor_spec.rb
# frozen_string_literal: true require "danger/danger_core/executor" # If you cannot find a method, please check spec/support/ci_helper.rb. RSpec.describe Danger::Executor, use: :ci_helper do describe "#validate!" do context "with CI + is a PR" do it "not raises error on Appcircle" do with_appcircle_setup_and_is_a_pull_request do |system_env| expect { described_class.new(system_env).validate!(testing_ui) }.not_to raise_error end end it "not raises error on Bamboo" do with_bamboo_setup_and_is_a_pull_request do |system_env| expect { described_class.new(system_env).validate!(testing_ui) }.not_to raise_error end end it "not raises error on Bitrise" do with_bitrise_setup_and_is_a_pull_request do |system_env| expect { described_class.new(system_env).validate!(testing_ui) }.not_to raise_error end end it "not raises error on Buildkite" do with_buildkite_setup_and_is_a_pull_request do |system_env| expect { described_class.new(system_env).validate!(testing_ui) }.not_to raise_error end end it "not raises error on Circle" do with_circle_setup_and_is_a_pull_request do |system_env| expect { described_class.new(system_env).validate!(testing_ui) }.not_to raise_error end end it "not raises error on Codefresh" do with_codefresh_setup_and_is_a_pull_request do |system_env| expect { described_class.new(system_env).validate!(testing_ui) }.not_to raise_error end end it "not raises error on Codemagic" do with_codemagic_setup_and_is_a_pull_request do |system_env| expect { described_class.new(system_env).validate!(testing_ui) }.not_to raise_error end end it "not raises error on Drone" do with_drone_setup_and_is_a_pull_request do |system_env| expect { described_class.new(system_env).validate!(testing_ui) }.not_to raise_error end end it "not raises error on GitLab CI" do with_gitlabci_setup_and_is_a_merge_request do |system_env| expect { described_class.new(system_env).validate!(testing_ui) }.not_to raise_error end end it "not raises error on Jenkins (GitHub)" do with_jenkins_setup_github_and_is_a_pull_request do |system_env| expect { described_class.new(system_env).validate!(testing_ui) }.not_to raise_error end end it "not raises error on Jenkins (GitLab)" do with_jenkins_setup_gitlab_and_is_a_merge_request do |system_env| expect { described_class.new(system_env).validate!(testing_ui) }.not_to raise_error end end it "not raises error on Jenkins (GitLab v3)" do with_jenkins_setup_gitlab_v3_and_is_a_merge_request do |system_env| expect { described_class.new(system_env).validate!(testing_ui) }.not_to raise_error end end it "not raises error on Local Git Repo" do with_localgitrepo_setup do |system_env| ui = testing_ui expect { described_class.new(system_env).validate!(ui) }.to raise_error(SystemExit) expect(ui.string).to include("Not a LocalGitRepo Pull Request - skipping `danger` run") end end it "not raises error on Screwdriver" do with_screwdriver_setup_and_is_a_pull_request do |system_env| expect { described_class.new(system_env) }.not_to raise_error end end it "not raises error on Semaphore" do with_semaphore_setup_and_is_a_pull_request do |system_env| expect { described_class.new(system_env) }.not_to raise_error end end it "not raises error on Surf" do with_surf_setup_and_is_a_pull_request do |system_env| expect { described_class.new(system_env) }.not_to raise_error end end it "not raises error on TeamCity (GitLab)" do with_teamcity_setup_github_and_is_a_pull_request do |system_env| expect { described_class.new(system_env) }.not_to raise_error end end it "not raises error on TeamCity (GitLab)" do with_teamcity_setup_gitlab_and_is_a_merge_request do |system_env| expect { described_class.new(system_env) }.not_to raise_error end end it "not raises error on Travis" do with_travis_setup_and_is_a_pull_request do |system_env| expect { described_class.new(system_env) }.not_to raise_error end end it "not raises error on Xcode Server" do with_xcodeserver_setup_and_is_a_pull_request do |system_env| expect { described_class.new(system_env) }.not_to raise_error end end end context "without CI" do it "raises error with clear message" do we_dont_have_ci_setup do |system_env| expect { described_class.new(system_env).run }.to \ raise_error(SystemExit, /Could not find the type of CI for Danger to run on./) end end end context "NOT a PR" do it "exits with clear message" do not_a_pull_request do |system_env| ui = testing_ui expect { described_class.new(system_env).validate!(ui) }.to raise_error(SystemExit) expect(ui.string).to include("Not a Travis Pull Request - skipping `danger` run") end end it "raises error on GitLab CI" do with_gitlabci_setup_and_is_not_a_merge_request do |system_env| ui = testing_ui expect { described_class.new(system_env).validate!(ui) }.to raise_error(SystemExit) expect(ui.string).to include("Not a GitLabCI Merge Request - skipping `danger` run") end end end end context "a test for SwiftWeekly #89" do class FakeProse attr_accessor :ignored_words def lint_files true end def check_spelling true end end module Danger class Dangerfile def prose FakeProse.new end end end let!(:project_root) { Dir.pwd } def prepare_fake_swiftweekly_repository(dir) head_sha = base_sha = nil Dir.chdir dir do `echo "# SwiftWeekly" >> README.md` `mkdir _drafts _posts` FileUtils.cp "#{project_root}/spec/fixtures/github/Dangerfile", dir `git init -b master` `git add .` `git commit --no-gpg-sign -m "first commit"` `git remote add origin git@github.com:SwiftWeekly/swiftweekly.github.io.git` # Create 2016-09-15-issue-38.md `git checkout -b jp-issue-38 --quiet` IO.write("_drafts/2016-09-15-issue-38.md", "init 2016-09-15-issue-38.md") `git add _drafts/2016-09-15-issue-38.md` `git commit --no-gpg-sign -m "flesh out issue 38 based on suggestions from #75, #79"` # Update 2016-09-15-issue-38.md IO.write("_drafts/2016-09-15-issue-38.md", "update 2016-09-15-issue-38.md") `git add _drafts/2016-09-15-issue-38.md` `git commit --no-gpg-sign -m "address first round of review feedback"` # Move 2016-09-15-issue-38.md from _drafts/ to _posts/ `git mv _drafts/2016-09-15-issue-38.md _posts/2016-09-15-issue-38.md` `git add .` `git commit --no-gpg-sign -m "move issue 38 to _posts"` shas = `git log --oneline`.scan(/\b[0-9a-f]{5,40}\b/) head_sha = shas.first base_sha = shas.last end [head_sha, base_sha] end def pretend_we_are_in_the_travis approval = ENV["HAS_JOSH_K_SEAL_OF_APPROVAL"] pr = ENV["TRAVIS_PULL_REQUEST"] slug = ENV["TRAVIS_REPO_SLUG"] api_token = ENV["DANGER_GITHUB_API_TOKEN"] ENV["HAS_JOSH_K_SEAL_OF_APPROVAL"] = "true" ENV["TRAVIS_PULL_REQUEST"] = "42" ENV["TRAVIS_REPO_SLUG"] = "danger/danger" ENV["DANGER_GITHUB_API_TOKEN"] = "1234567890" * 4 # octokit token is of size 40 yield ensure ENV["HAS_JOSH_K_SEAL_OF_APPROVAL"] = approval ENV["TRAVIS_PULL_REQUEST"] = pr ENV["TRAVIS_REPO_SLUG"] = slug api_token = api_token end def to_json(raw) JSON.parse(raw) end def swiftweekly_pr_89_as_json(head_sha, base_sha) pr_json = to_json(IO.read("#{project_root}/spec/fixtures/github/swiftweekly.github.io-pulls-89.json")) pr_json["base"]["sha"] = base_sha pr_json["head"]["sha"] = head_sha pr_json end def swiftweekly_issues_89_as_json to_json(IO.read("#{project_root}/spec/fixtures/github/swiftweekly.github.io-issues-89.json")) end def swiftweekly_issue_89_comments_as_json to_json(IO.read("#{project_root}/spec/fixtures/github/swiftweekly.github.io-issues-89-comments.json")) end it "works" do Dir.mktmpdir do |dir| Dir.chdir dir do head_sha, base_sha = prepare_fake_swiftweekly_repository(dir) fake_client = double("Octokit::Client") allow(Octokit::Client).to receive(:new) { fake_client } allow(fake_client).to receive(:pull_request) { swiftweekly_pr_89_as_json(head_sha, base_sha) } allow(fake_client).to receive(:get) { swiftweekly_issues_89_as_json } allow(fake_client).to receive(:issue_comments) { swiftweekly_issue_89_comments_as_json } allow(fake_client).to receive(:pull_request_comments) { swiftweekly_issue_89_comments_as_json } allow(fake_client).to receive(:delete_comment) { true } allow(fake_client).to receive(:create_status) { true } pretend_we_are_in_the_travis do Danger::Executor.new(ENV).run(dangerfile_path: "Dangerfile") end end end end after do module Danger class Dangerfile undef_method :prose end end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/danger_core/danger_spec.rb
spec/lib/danger/danger_core/danger_spec.rb
# frozen_string_literal: true RSpec.describe Danger do it "has a version number" do expect(Danger::VERSION).not_to be nil end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/danger_core/message_aggregator_spec.rb
spec/lib/danger/danger_core/message_aggregator_spec.rb
# frozen_string_literal: true require "danger/danger_core/message_aggregator" require "danger/danger_core/messages/violation" module MessageFactories def violation(type, file, line) Danger::Violation.new("test violation", false, file, line, type: type) end %I[error warning message].each do |type| define_method(type) do |file, line| violation(type, file, line) end end def markdown(file, line) Danger::Markdown.new("test markdown", file, line) end end RSpec.describe Danger::MessageAggregator do include MessageFactories describe "#aggregate" do subject { described_class.new(**args).aggregate } let(:args) do { warnings: warnings.shuffle, errors: errors.shuffle, messages: messages.shuffle, markdowns: markdowns.shuffle } end let(:warnings) { [] } let(:errors) { [] } let(:messages) { [] } let(:markdowns) { [] } context "with no messages" do it "returns an array with #fake_warnings_array and #fake_errors_array" do expect(subject).to be_a Array expect(subject).to respond_to :fake_warnings_array expect(subject).to respond_to :fake_errors_array end it "returns an array containing one group" do expect(subject.count).to eq 1 group = subject.first expect(group.messages.count).to eq 0 expect(group.file).to be nil expect(group.line).to be nil end end context "with one message of each type" do let(:errors) { [error(nil, nil)] } let(:warnings) { [warning(nil, nil)] } let(:messages) { [message(nil, nil)] } let(:markdowns) { [markdown(nil, nil)] } it "returns an array containing one group - with all the messages in it" do expect(subject.count).to eq 1 group = subject.first expect(group.messages.count).to eq 4 expect(group.file).to be nil expect(group.line).to be nil end it "sorts the messages by type" do group = subject.first expect(group.messages[0].type).to eq :error expect(group.messages[1].type).to eq :warning expect(group.messages[2].type).to eq :message expect(group.messages[3].type).to eq :markdown end end context "with a few messages in different files message of each type" do let(:file_a) { "README.md" } let(:file_b) { "buggy_app.rb" } # groups expected: # nil: # nil: [] # # file_a: # 1: [markdown] # 2: [message] # 3: [error, error, warning, message, markdown] # # file_b: # 1: [error, warning] # 2: [message] # 3: [error] let(:errors) do [ [file_a, 3], [file_a, 3], [file_b, 1], [file_b, 3] ].map { |a| error(*a) } end let(:warnings) do [ [file_a, 3], [file_b, 1] ].map { |a| warning(*a) } end let(:messages) do [ [file_a, 2], [file_a, 3], [file_b, 2] ].map { |a| message(*a) } end let(:markdowns) do [ [file_a, 1], [file_a, 3] ].map { |a| markdown(*a) } end it "returns an array containing one group - with all the messages in it" do expect(subject.count).to eq 7 expect(subject.fake_warnings_array.count).to eq warnings.count expect(subject.fake_errors_array.count).to eq errors.count (nil_group, a1, a2, a3, b1, b2, b3) = subject expect(nil_group.messages).to eq [] expect(a1.messages.map(&:type)).to eq [:markdown] expect([a1.file, a1.line]).to eq([file_a, 1]) expect([a2.file, a2.line]).to eq([file_a, 2]) expect(a2.messages.map(&:type)).to eq [:message] expect([a3.file, a3.line]).to eq([file_a, 3]) expect(a3.messages.map(&:type)).to eq %i(error error warning message markdown) expect(b1.messages.map(&:type)).to eq %i(error warning) expect([b1.file, b1.line]).to eq([file_b, 1]) expect([b2.file, b2.line]).to eq([file_b, 2]) expect(b2.messages.map(&:type)).to eq [:message] expect([b3.file, b3.line]).to eq([file_b, 3]) expect(b3.messages.map(&:type)).to eq [:error] end # it "sorts the messages by type" do # group = subject.first # expect(group.messages[0].type).to eq :error # expect(group.messages[1].type).to eq :warning # expect(group.messages[2].type).to eq :message # expect(group.messages[3].type).to eq :markdown # end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/danger_core/dangerfile_spec.rb
spec/lib/danger/danger_core/dangerfile_spec.rb
# frozen_string_literal: true require "pathname" require "tempfile" require "danger/danger_core/plugins/dangerfile_messaging_plugin" require "danger/danger_core/plugins/dangerfile_danger_plugin" require "danger/danger_core/plugins/dangerfile_git_plugin" require "danger/danger_core/plugins/dangerfile_github_plugin" RSpec.describe Danger::Dangerfile, host: :github do it "keeps track of the original Dangerfile" do file = make_temp_file "" dm = testing_dangerfile dm.parse file.path expect(dm.defined_in_file).to eq file.path end it "runs the ruby code inside the Dangerfile" do dangerfile_code = "message('hi')" expect_any_instance_of(Danger::DangerfileMessagingPlugin).to receive(:message).and_return("") dm = testing_dangerfile dm.parse Pathname.new(""), dangerfile_code end it "raises elegantly with bad ruby code inside the Dangerfile" do dangerfile_code = "asdas = asdasd + asdasddas" dm = testing_dangerfile expect do dm.parse Pathname.new(""), dangerfile_code end.to raise_error(Danger::DSLError) end it "respects ignored violations" do code = "message 'A message'\n" \ "warn 'An ignored warning'\n" \ "warn 'A warning'\n" \ "fail 'An ignored error'\n" \ "fail 'An error'\n" dm = testing_dangerfile dm.env.request_source.ignored_violations = ["A message", "An ignored warning", "An ignored error"] dm.parse Pathname.new(""), code results = dm.status_report expect(results[:messages]).to eq(["A message"]) expect(results[:errors]).to eq(["An error"]) expect(results[:warnings]).to eq(["A warning"]) end it "allows failure" do code = "fail 'fail1'\n" \ "failure 'fail2'\n" dm = testing_dangerfile dm.parse Pathname.new(""), code results = dm.status_report expect(results[:errors]).to eq(["fail1", "fail2"]) end describe "#print_results" do it "Prints out 3 lists" do code = "message 'A message'\n" \ "warn 'Another warning'\n" \ "warn 'A warning'\n" \ "fail 'Another error'\n" \ "fail 'An error'\n" dm = testing_dangerfile dm.env.request_source.ignored_violations = ["A message", "An ignored warning", "An ignored error"] dm.parse Pathname.new(""), code expect(dm).to receive(:print_list).with("Errors:".red, violations_factory(["Another error", "An error"], sticky: false)) expect(dm).to receive(:print_list).with("Warnings:".yellow, violations_factory(["Another warning", "A warning"], sticky: false)) expect(dm).to receive(:print_list).with("Messages:", violations_factory(["A message"], sticky: false)) dm.print_results end end describe "verbose" do it "outputs metadata when verbose" do file = make_temp_file "" dm = testing_dangerfile dm.verbose = true expect(dm).to receive(:print_known_info) dm.parse file.path end it "does not print metadata by default" do file = make_temp_file "" dm = testing_dangerfile expect(dm).to_not receive(:print_known_info) dm.parse file.path end end # Sidenote: If you're writing tests that touch the plugin infrastructure at runtime # you're going to have a bad time if they share the class name. Make them unique. describe "initializing plugins" do it "should add a plugin to the @plugins array" do class DangerTestAddingToArrayPlugin < Danger::Plugin; end allow(Danger::Plugin).to receive(:all_plugins).and_return([DangerTestAddingToArrayPlugin]) dm = testing_dangerfile allow(dm).to receive(:core_dsls).and_return([]) dm.init_plugins expect(dm.instance_variable_get("@plugins").length).to eq(1) end it "should add an instance variable to the dangerfile" do class DangerTestAddingInstanceVarPlugin < Danger::Plugin; end allow(ObjectSpace).to receive(:each_object).and_return([DangerTestAddingInstanceVarPlugin]) dm = testing_dangerfile allow(dm).to receive(:core_dsls).and_return([]) dm.init_plugins expect { dm.test_adding_instance_var_plugin }.to_not raise_error expect(dm.test_adding_instance_var_plugin.class).to eq(DangerTestAddingInstanceVarPlugin) end end describe "printing verbose metadata" do before do Danger::Plugin.clear_external_plugins end it "exposes core attributes" do dm = testing_dangerfile methods = dm.core_dsl_attributes.map { |hash| hash[:methods] }.flatten.sort expect(methods).to eq %i(fail failure markdown message status_report violation_report warn) end # These are things that require scoped access it "exposes no external attributes by default" do dm = testing_dangerfile methods = dm.external_dsl_attributes.map { |hash| hash[:methods] }.flatten.sort expect(methods).to eq %i( added_files api base_commit branch_for_base branch_for_head commits deleted_files deletions diff diff_for_file dismiss_out_of_range_messages head_commit html_link import_dangerfile import_plugin info_for_file insertions lines_of_code modified_files mr_author mr_body mr_json mr_labels mr_title pr_author pr_body pr_diff pr_draft? pr_json pr_labels pr_title renamed_files review scm_provider tags ) end it "exposes all external plugin attributes by default" do class DangerCustomAttributePlugin < Danger::Plugin attr_reader :my_thing end dm = testing_dangerfile methods = dm.external_dsl_attributes.map { |hash| hash[:methods] }.flatten.sort expect(methods).to include(:my_thing) end def sort_data(data) data.sort do |a, b| if a.first < b.first -1 else (a.first > b.first ? 1 : (a.first <=> b.first)) end end end describe "table metadata" do before do @dm = testing_dangerfile @dm.env.request_source.support_tokenless_auth = true # Stub out the GitHub stuff pr_reviews_response = JSON.parse(fixture("github_api/pr_reviews_response")) allow(@dm.env.request_source.client).to receive(:pull_request_reviews).with("artsy/eigen", "800").and_return(pr_reviews_response) pr_response = JSON.parse(fixture("github_api/pr_response")) allow(@dm.env.request_source.client).to receive(:pull_request).with("artsy/eigen", "800").and_return(pr_response) issue_response = JSON.parse(fixture("github_api/issue_response")) allow(@dm.env.request_source.client).to receive(:get).with("https://api.github.com/repos/artsy/eigen/issues/800").and_return(issue_response) diff_response = diff_fixture("pr_diff_response") allow(@dm.env.request_source.client).to receive(:pull_request).with("artsy/eigen", "800", accept: "application/vnd.github.v3.diff").and_return(diff_response) # Use a known diff from Danger's history: # https://github.com/danger/danger/compare/98c4f7760bb16300d1292bb791917d8e4990fd9a...9a424ecd5ad7404fa71cf2c99627d2882f0f02ce @dm.env.fill_environment_vars @dm.env.scm.diff_for_folder(".", from: "9a424ecd5ad7404fa71cf2c99627d2882f0f02ce", to: "98c4f7760bb16300d1292bb791917d8e4990fd9a") end it "creates a table from a selection of core DSL attributes info" do # Check out the method hashes of all plugin info data = @dm.method_values_for_plugin_hashes(@dm.core_dsl_attributes) # Ensure consistent ordering data = sort_data(data) expect(data).to eq [ ["status_report", { errors: [], warnings: [], messages: [], markdowns: [] }], ["violation_report", { errors: [], warnings: [], messages: [] }] ] end it "creates a table from a selection of external plugins DSL attributes info" do class DangerCustomAttributeTwoPlugin < Danger::Plugin def something "value_for_something" end end data = @dm.method_values_for_plugin_hashes(@dm.external_dsl_attributes) # Ensure consistent ordering, and only extract the keys data = sort_data(data).map { |d| d.first.to_sym } expect(data).to eq %i( added_files api base_commit branch_for_base branch_for_head commits deleted_files deletions diff head_commit insertions lines_of_code modified_files mr_author mr_body mr_json mr_labels mr_title pr_author pr_body pr_diff pr_draft? pr_json pr_labels pr_title renamed_files review scm_provider tags ) end it "skips raw PR/MR JSON, and diffs" do data = @dm.method_values_for_plugin_hashes(@dm.external_dsl_attributes) data_hash = data .collect { |v| [v.first, v.last] } .flat_map .each_with_object({}) { |vals, accum| accum.store(vals[0], vals[1]) } expect(data_hash["pr_json"]).to eq("[Skipped JSON]") expect(data_hash["mr_json"]).to eq("[Skipped JSON]") expect(data_hash["pr_diff"]).to eq("[Skipped Diff]") end end end describe "#post_results" do it "delegates to corresponding request source" do env_manager = double("Danger::EnvironmentManager", pr?: true) request_source = double("Danger::RequestSources::GitHub") allow(env_manager).to receive_message_chain(:scm, :class) { Danger::GitRepo } allow(env_manager).to receive(:request_source) { request_source } dm = Danger::Dangerfile.new(env_manager, testing_ui) expect(request_source).to receive(:update_pull_request!) dm.post_results("danger-identifier", nil, nil) end it "delegates unique entries" do code = "message 'message one'\n" \ "message 'message two'\n" \ "message 'message one'\n" \ "warn 'message one'\n" \ "warn 'message two'\n" \ "warn 'message two'\n" dm = testing_dangerfile dm.env.request_source.ignored_violations = [] dm.parse Pathname.new(""), code results = dm.status_report expect(dm.env.request_source).to receive(:update_pull_request!).with( warnings: [anything, anything], errors: [], messages: [anything, anything], markdowns: [], danger_id: "danger-identifier", new_comment: nil, remove_previous_comments: nil ) dm.post_results("danger-identifier", nil, nil) end end describe "#setup_for_running" do it "ensure branches setup and generate diff" do env_manager = double("Danger::EnvironmentManager", pr?: true) scm = double("Danger::GitRepo", class: Danger::GitRepo) request_source = double("Danger::RequestSources::GitHub") allow(env_manager).to receive(:scm) { scm } allow(env_manager).to receive(:request_source) { request_source } dm = Danger::Dangerfile.new(env_manager, testing_ui) expect(env_manager).to receive(:ensure_danger_branches_are_setup) expect(scm).to receive(:diff_for_folder) dm.setup_for_running("custom_danger_base", "custom_danger_head") end end describe "#run" do context "when exception occurred" do let(:dangerfile_fixture_filename) { "dangerfile_with_error" } let(:dangerfile_path) { Pathname.new(File.join("spec", "fixtures", dangerfile_fixture_filename)) } let(:env_manager) do double("Danger::EnvironmentManager", { pr?: false, clean_up: true, fill_environment_vars: true, ensure_danger_branches_are_setup: false }) end let(:scm) do double("Danger::GitRepo", { class: Danger::GitRepo, diff_for_folder: true }) end let(:request_source) { double("Danger::RequestSources::GitHub") } let(:dm) { Danger::Dangerfile.new(env_manager, testing_ui) } before do allow(Danger).to receive(:danger_outdated?).and_return(false) allow(env_manager).to receive(:scm) { scm } allow(env_manager).to receive(:request_source) { request_source } end it "does not updates PR with an error" do expect(request_source).to receive(:update_pull_request!) expect do dm.run("custom_danger_base", "custom_danger_head", dangerfile_path, 1, false, false) end.to raise_error(Danger::DSLError) end context "when path is reassigned" do let(:dangerfile_fixture_filename) { "dangerfile_with_error_and_path_reassignment" } it "doesn't crash" do expect(request_source).to receive(:update_pull_request!) expect do dm.run("custom_danger_base", "custom_danger_head", dangerfile_path, 1, false, false) end.to raise_error(Danger::DSLError) end end context "when ENV['DANGER_DO_NOT_POST_INVALID_DANGERFILE_ERROR'] is set" do before do allow(ENV).to receive(:[]).with("DANGER_DO_NOT_POST_INVALID_DANGERFILE_ERROR") { "" } end it "does not updates PR with an error" do expect(request_source).not_to receive(:update_pull_request!) expect do dm.run("custom_danger_base", "custom_danger_head", dangerfile_path, 1, false, false) end.to raise_error(Danger::DSLError) end end after { allow(Danger).to receive(:danger_outdated?).and_call_original } end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/danger_core/messages/violation_spec.rb
spec/lib/danger/danger_core/messages/violation_spec.rb
# frozen_string_literal: true require_relative "./shared_examples" require "danger/danger_core/messages/violation" require "danger/danger_core/messages/markdown" def random_alphas(n) (0...n).map { ("a".."z").to_a[rand(26)] } end RSpec.describe Danger::Violation do subject(:violation) { described_class.new(message, sticky, file, line, type: type) } let(:message) { "hello world" } let(:sticky) { false } let(:file) { nil } let(:line) { nil } let(:type) { :warning } describe "#initialize" do subject { described_class.new("hello world", true) } it "defaults file to nil" do expect(subject.file).to be nil end it "defaults line to nil" do expect(subject.line).to be nil end it "defaults type to :warning" do expect(subject.type).to be :warning end context "when type is an invalid value" do let(:type) { :i_am_an_invalid_type! } it "raises ArgumentError" do expect { violation }.to raise_error(ArgumentError) end end context "when sticky is unset" do it "raises" do expect { described_class.new("hello world") }.to raise_error(ArgumentError) end end context "when message is unset" do it "raises" do expect { described_class.new }.to raise_error(ArgumentError) end end end describe "#<=>" do subject { violation <=> other } let(:file) { "hello.txt" } let(:line) { 50 } RSpec.shared_examples_for "compares by file and line when other is" do |_other_type| context "when other_type is :#{_other_type}" do let(:other_type) { _other_type } include_examples "compares by file and line" end end shared_examples_for "compares less than" do |_other_type| context "when other_type is :#{_other_type}" do let(:other_type) { _other_type } # set other_file and other_line to random stuff to prove they have no # effect let(:other_file) { random_alphas(file.length) } let(:other_line) { rand(4000) } it { is_expected.to eq(-1) } end end shared_examples_for "compares more than" do |_other_type| context "when other_type is :#{_other_type}" do let(:other_type) { _other_type } let(:other_file) { random_alphas(file.length) } let(:other_line) { rand(4000) } it { is_expected.to eq(1) } end end shared_examples_for "compares less than Markdown" do context "when other is a Markdown" do let(:other) { Danger::Markdown.new("hello world", file, line) } it { is_expected.to eq(-1) } end end context "when type is :error" do let(:type) { :error } context "when other is a Violation" do let(:other) { Danger::Violation.new("hello world", false, other_file, other_line, type: other_type) } include_examples "compares by file and line when other is", :error include_examples "compares less than", :warning include_examples "compares less than", :message end include_examples "compares less than Markdown" end context "when type is :warning" do let(:type) { :warning } context "when other is a Violation" do let(:other) { Danger::Violation.new("hello world", false, other_file, other_line, type: other_type) } include_examples "compares more than", :error include_examples "compares by file and line when other is", :warning include_examples "compares less than", :message end include_examples "compares less than Markdown" end context "when type is :message" do let(:type) { :message } context "when other is a Violation" do let(:other) { Danger::Violation.new("hello world", false, other_file, other_line, type: other_type) } include_examples "compares more than", :error include_examples "compares more than", :warning include_examples "compares by file and line when other is", :message end include_examples "compares less than Markdown" end end describe "#to_s" do it "formats a message" do expect(violation_factory("hello!").to_s).to eq("Violation hello! { sticky: false, type: warning }") end it "formats a sticky message" do expect(violation_factory("hello!", sticky: true).to_s).to eq("Violation hello! { sticky: true, type: warning }") end it "formats a message with file and line" do expect(violation_factory("hello!", file: "foo.rb", line: 2).to_s).to eq("Violation hello! { sticky: false, file: foo.rb, line: 2, type: warning }") end it "formats a message with file, line and custom type" do expect(violation_factory("hello!", file: "foo.rb", line: 2, type: :error).to_s).to eq("Violation hello! { sticky: false, file: foo.rb, line: 2, type: error }") end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/danger_core/messages/shared_examples.rb
spec/lib/danger/danger_core/messages/shared_examples.rb
# frozen_string_literal: true # This helper method and the examples are used for the specs for #<=> on Markdown and Violation def random_alphas(n) (0...n).map { ("a".."z").to_a[rand(26)] } end RSpec.shared_examples_for "compares by line" do context "when line is nil" do let(:line) { nil } context "when other_line is nil" do let(:other_line) { nil } it { is_expected.to eq(0) } end context "when other_line is not nil" do let(:other_line) { 1 } it { is_expected.to eq(-1) } end end context "when line is not nil" do let(:line) { rand(4000) } context "when other_line is nil" do let(:other_line) { nil } it { is_expected.to eq(1) } end context "when lines are the same" do let(:other_line) { line } it { is_expected.to eq 0 } end context "when line < other_line" do let(:other_line) { line + 10 } it { is_expected.to eq(-1) } end context "when line < other_line" do let(:other_line) { line - 10 } it { is_expected.to eq(1) } end end end RSpec.shared_examples_for "compares by file and line" do let(:other_line) { rand(4000) } context "when file is nil" do let(:file) { nil } context "when other_file is nil" do let(:other_file) { nil } it { is_expected.to eq(0) } end context "when other_file is not nil" do let(:other_file) { "world.txt" } it { is_expected.to eq(-1) } end end context "when file is not nil" do let(:file) { "hello.txt" } context "when other_file is nil" do let(:other_file) { nil } it { is_expected.to eq(1) } end context "when files are the same" do let(:other_file) { file } include_examples "compares by line" end context "when file < other_file" do let(:other_file) { "world.txt" } it { is_expected.to eq(-1) } end context "when file > other_file" do let(:other_file) { "aardvark.txt" } it { is_expected.to eq 1 } end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/danger_core/messages/markdown_spec.rb
spec/lib/danger/danger_core/messages/markdown_spec.rb
# frozen_string_literal: true require_relative "./shared_examples" require "danger/danger_core/messages/violation" require "danger/danger_core/messages/markdown" RSpec.describe Danger::Markdown do subject(:markdown) { described_class.new(message, file, line) } let(:message) { "hello world" } let(:file) { nil } let(:line) { nil } describe "#initialize" do subject { described_class.new("hello world") } it "defaults file to nil" do expect(subject.file).to be nil end it "defaults line to nil" do expect(subject.line).to be nil end end describe "#<=>" do subject { markdown <=> other } context "when other is a Violation" do let(:other) { Danger::Violation.new("hello world", false, other_file, other_line) } let(:other_file) { "test" } let(:other_line) { rand(4000) } it { is_expected.to eq(1) } end context "when other is a Markdown" do let(:other) { Danger::Markdown.new("example message", other_file, other_line) } it_behaves_like "compares by file and line" end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/danger_core/plugins/dangerfile_github_plugin_spec.rb
spec/lib/danger/danger_core/plugins/dangerfile_github_plugin_spec.rb
# frozen_string_literal: true RSpec.describe Danger::DangerfileGitHubPlugin, host: :github do describe "dsl" do before do dm = testing_dangerfile @dsl = described_class.new(dm) pr_response = JSON.parse(fixture("github_api/pr_response")) allow(@dsl).to receive(:pr_json).and_return(pr_response) end describe "html_link" do it "works with a single path" do link = @dsl.html_link("file.txt") expect(link).to eq("<a href='https://github.com/artsy/eigen/blob/561827e46167077b5e53515b4b7349b8ae04610b/file.txt'>file.txt</a>") end it "can show just a path" do link = @dsl.html_link("/path/file.txt", full_path: false) expect(link).to eq("<a href='https://github.com/artsy/eigen/blob/561827e46167077b5e53515b4b7349b8ae04610b/path/file.txt'>file.txt</a>") end it "works with 2 paths" do link = @dsl.html_link(["file.txt", "example.json"]) expect(link).to eq("<a href='https://github.com/artsy/eigen/blob/561827e46167077b5e53515b4b7349b8ae04610b/file.txt'>file.txt</a> & " \ "<a href='https://github.com/artsy/eigen/blob/561827e46167077b5e53515b4b7349b8ae04610b/example.json'>example.json</a>") end it "works with 3+ paths" do link = @dsl.html_link(["file.txt", "example.json", "script.rb#L30"]) expect(link).to eq("<a href='https://github.com/artsy/eigen/blob/561827e46167077b5e53515b4b7349b8ae04610b/file.txt'>file.txt</a>, " \ "<a href='https://github.com/artsy/eigen/blob/561827e46167077b5e53515b4b7349b8ae04610b/example.json'>example.json</a> & " \ "<a href='https://github.com/artsy/eigen/blob/561827e46167077b5e53515b4b7349b8ae04610b/script.rb#L30'>script.rb#L30</a>") end describe "#dismiss_out_of_range_messages" do context "without argument" do it { expect(@dsl.dismiss_out_of_range_messages).not_to be_nil } end context "with bool" do it { expect(@dsl.dismiss_out_of_range_messages(false)).not_to be_nil } end context "with Hash" do it { expect(@dsl.dismiss_out_of_range_messages({ error: true, warning: false })).not_to be_nil } end end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/danger_core/plugins/dangerfile_danger_plugin_spec.rb
spec/lib/danger/danger_core/plugins/dangerfile_danger_plugin_spec.rb
# frozen_string_literal: true require "danger/danger_core/environment_manager" require "danger/danger_core/plugins/dangerfile_danger_plugin" RSpec.describe Danger::Dangerfile::DSL, host: :github do let(:env) { stub_env } let(:dm) { testing_dangerfile(env) } describe "#import" do describe "#import_local" do it "supports exact paths" do dm.danger.import_plugin("spec/fixtures/plugins/example_exact_path.rb") expect { dm.example_exact_path }.to_not raise_error expect(dm.example_exact_path.echo).to eq("Hi there exact") end it "supports file globbing" do dm.danger.import_plugin("spec/fixtures/plugins/*globbing*.rb") expect(dm.example_globbing.echo).to eq("Hi there globbing") end it "not raises an error when calling a plugin that's a subclass of Plugin" do expect do dm.danger.import_plugin("spec/fixtures/plugins/example_not_broken.rb") end.not_to raise_error end it "raises an error when calling a plugin that's not a subclass of Plugin" do expect do dm.danger.import_plugin("spec/fixtures/plugins/example_broken.rb") end.to raise_error(RuntimeError, %r{spec/fixtures/plugins/example_broken.rb doesn't contain any valid danger plugin}) end end describe "#import_url" do it "downloads a remote .rb file" do expect { dm.example_ping.echo }.to raise_error NoMethodError url = "https://krausefx.com/example_remote.rb" stub_request(:get, "https://krausefx.com/example_remote.rb"). to_return(status: 200, body: File.read("spec/fixtures/plugins/example_echo_plugin.rb")) dm.danger.import_plugin(url) expect(dm.example_ping.echo).to eq("Hi there 🎉") end it "rejects unencrypted plugins" do expect do dm.danger.import_plugin("http://unencrypted.org") end.to raise_error("URL is not https, for security reasons `danger` only supports encrypted requests") end end end describe "#import_dangerfile" do before do api_url = "https://api.github.com/repos/example/example/contents/Dangerfile?ref" api_url_custom = "https://api.github.com/repos/example/example/contents/path/to/Dangerfile?ref=custom-branch" download_url = "https://raw.githubusercontent.com/example/example/master/Dangerfile" download_url_custom = "https://raw.githubusercontent.com/example/example/custom-branch/path/to/Dangerfile" mock_dangerfile = "message('OK')" stub_request(:get, api_url).to_return(status: 404) stub_request(:get, api_url_custom).to_return(status: 404) stub_request(:get, download_url).to_return(status: 200, body: mock_dangerfile) stub_request(:get, download_url_custom).to_return(status: 200, body: mock_dangerfile) end it "defaults to org/repo and warns of deprecation" do outer_dangerfile = "danger.import_dangerfile('example/example')" dm.parse(Pathname.new("."), outer_dangerfile) expect(dm.status_report[:warnings]).to eq(["Use `import_dangerfile(github: 'example/example')` instead of `import_dangerfile 'example/example'`."]) expect(dm.status_report[:messages]).to eq(["OK"]) end it "github: 'repo/name'" do outer_dangerfile = "danger.import_dangerfile(github: 'example/example')" dm.parse(Pathname.new("."), outer_dangerfile) expect(dm.status_report[:messages]).to eq(["OK"]) end it "github: 'repo/name', branch: 'custom-branch', path: 'path/to/Dangerfile'" do outer_dangerfile = "danger.import_dangerfile(github: 'example/example', branch: 'custom-branch', path: 'path/to/Dangerfile')" dm.parse(Pathname.new("."), outer_dangerfile) expect(dm.status_report[:messages]).to eq(["OK"]) end it "github: 'repo/name', ref: 'custom-branch', path: 'path/to/Dangerfile'" do outer_dangerfile = "danger.import_dangerfile(github: 'example/example', ref: 'custom-branch', path: 'path/to/Dangerfile')" dm.parse(Pathname.new("."), outer_dangerfile) expect(dm.status_report[:messages]).to eq(["OK"]) end context "Gitlab", host: :gitlab do let(:env) { stub_env.merge("CI_MERGE_REQUEST_IID" => 42) } before do allow_any_instance_of(Danger::GitRepo).to receive(:origins).and_return("https://gitlab.com/author/repo.github.io.git") download_url = "https://gitlab.com/api/v4/projects/1/repository/files/Dangerfile/raw?private_token=a86e56d46ac78b&ref=master" download_url_custom = "https://gitlab.com/api/v4/projects/1/repository/files/path%2Fto%2FDangerfile/raw?private_token=a86e56d46ac78b&ref=custom-branch" mock_dangerfile = "message('OK')" stub_request(:get, download_url).to_return(status: 200, body: mock_dangerfile) stub_request(:get, download_url_custom).to_return(status: 200, body: mock_dangerfile) end it "gitlab: 'repo/name'" do outer_dangerfile = "danger.import_dangerfile(gitlab: 1)" dm.parse(Pathname.new("."), outer_dangerfile) expect(dm.status_report[:messages]).to eq(["OK"]) end it "gitlab: 'repo/name', branch: 'custom-branch', path: 'path/to/Dangerfile'" do outer_dangerfile = "danger.import_dangerfile(gitlab: 1, branch: 'custom-branch', path: 'path/to/Dangerfile')" dm.parse(Pathname.new("."), outer_dangerfile) expect(dm.status_report[:messages]).to eq(["OK"]) end end it "path: 'path'" do outer_dangerfile = "danger.import_dangerfile(path: 'foo/bar')" inner_dangerfile = "message('OK')" expect(File).to receive(:open).with(Pathname.new("foo/bar/Dangerfile"), "r:utf-8").and_return(inner_dangerfile) dm.parse(Pathname.new("."), outer_dangerfile) expect(dm.status_report[:messages]).to eq(["OK"]) end it "path: 'full_path'" do outer_dangerfile = "danger.import_dangerfile(path: 'foo/bar/baz.rb')" inner_dangerfile = "message('OK')" expected_path = "foo/bar/baz.rb" expect(File).to receive(:file?).with(expected_path).and_return(true) expect(File).to receive(:open).with(Pathname.new(expected_path), "r:utf-8").and_return(inner_dangerfile) dm.parse(Pathname.new("."), outer_dangerfile) expect(dm.status_report[:messages]).to eq(["OK"]) end it "gem: 'name'" do outer_dangerfile = "danger.import_dangerfile(gem: 'example')" inner_dangerfile = "message('OK')" expect(File).to receive(:open).with(Pathname.new("/gems/foo/bar/Dangerfile"), "r:utf-8").and_return(inner_dangerfile) expect(Gem::Specification).to receive_message_chain(:find_by_name, :gem_dir).and_return("/gems/foo/bar") dm.parse(Pathname.new("."), outer_dangerfile) expect(dm.status_report[:messages]).to eq(["OK"]) end it "url: 'url'" do outer_dangerfile = "danger.import_dangerfile(url: 'https://raw.githubusercontent.com/example/example/master/Dangerfile')" dm.parse(Pathname.new("."), outer_dangerfile) expect(dm.status_report[:messages]).to eq(["OK"]) end end describe "#scm_provider" do context "GitHub", host: :github do it "is `:github`" do with_git_repo(origin: "git@github.com:artsy/eigen") do expect(dm.danger.scm_provider).to eq(:github) end end end context "GitLab", host: :gitlab do let(:env) { stub_env.merge("CI_MERGE_REQUEST_IID" => 42) } it "is `:gitlab`" do with_git_repo(origin: "git@gitlab.com:k0nserv/danger-test.git") do expect(dm.danger.scm_provider).to eq(:gitlab) end end end context "Bitbucket Server", host: :bitbucket_server do it "is `:bitbucket_server`" do with_git_repo(origin: "git@stash.example.com:artsy/eigen") do expect(dm.danger.scm_provider).to eq(:bitbucket_server) end end end context "VSTS", host: :vsts do it "is `:vsts`" do with_git_repo(origin: "https://artsy.visualstudio.com/artsy/_git/eigen") do expect(dm.danger.scm_provider).to eq(:vsts) end end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false
danger/danger
https://github.com/danger/danger/blob/20f1243775da2ce53f55ad5ba65112de5da6e118/spec/lib/danger/danger_core/plugins/dangerfile_vsts_plugin_spec.rb
spec/lib/danger/danger_core/plugins/dangerfile_vsts_plugin_spec.rb
# frozen_string_literal: true RSpec.describe Danger::DangerfileVSTSPlugin, host: :vsts do let(:dangerfile) { testing_dangerfile } let(:plugin) { described_class.new(dangerfile) } before do stub_pull_request end describe "plugin" do before do dangerfile.env.request_source.fetch_details end describe "#pr_json" do it "has a non empty json" do expect(plugin.pr_json).to be_truthy end end describe "#pr_title" do it "has a fetched title" do expect(plugin.pr_title).to eq("This is a danger test") end end describe "#pr_author" do it "has a fetched author" do expect(plugin.pr_author).to eq("pierremarcairoldi") end end describe "#pr_link" do it "has a fetched link to it self" do expect(plugin.pr_link).to eq("https://petester42.visualstudio.com/_git/danger-test/pullRequest/1") end end describe "#branch_for_base" do it "has a fetched branch for base" do expect(plugin.branch_for_base).to eq("master") end end describe "#branch_for_head" do it "has a fetched branch for head" do expect(plugin.branch_for_head).to eq("feature/danger") end end describe "#base_commit" do it "has a fetched base commit" do expect(plugin.base_commit).to eq("b803d2daf56ec1d69c84902b2037b9b7dc089ac1") end end describe "#head_commit" do it "has a fetched head commit" do expect(plugin.head_commit).to eq("1e1dfca72160939ef1988c2669e11ef2861b3707") end end describe "#markdown_link" do it "creates a usable markdown link" do expect(plugin.markdown_link("Classes/Main Categories/Feed/FeedViewController.m")).to include( "[Classes/Main Categories/Feed/FeedViewController.m](https://petester42.visualstudio.com/_git/danger-test/commit/1e1dfca72160939ef1988c2669e11ef2861b3707?path=/Classes/Main%20Categories/Feed/FeedViewController.m&_a=contents)" ) end it "creates a usable markdown link with line numbers" do expect(plugin.markdown_link("Classes/Main Categories/Feed/FeedViewController.m#L100")).to include( "[Classes/Main Categories/Feed/FeedViewController.m](https://petester42.visualstudio.com/_git/danger-test/commit/1e1dfca72160939ef1988c2669e11ef2861b3707?path=/Classes/Main%20Categories/Feed/FeedViewController.m&_a=contents&line=100)" ) end end end end
ruby
MIT
20f1243775da2ce53f55ad5ba65112de5da6e118
2026-01-04T15:42:56.145797Z
false