danger / danger-plugin-template

An opinionated template for creating a Danger plugin
Other
20 stars 10 forks source link

Fixes spec_helper.rb by passing missing testing_ui parameter #10

Closed notjosh closed 8 years ago

notjosh commented 8 years ago

'allo. Another huge PR :) This one's marginally more important than just a typo though.

Before this diff, I'd get errors like:

$ be rake spec
/usr/local/Cellar/ruby/2.2.2/bin/ruby -I/usr/local/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.4/lib:/usr/local/lib/ruby/gems/2.2.0/gems/rspec-support-3.5.0/lib /usr/local/lib/ruby/gems/2.2.0/gems/rspec-core-3.5.4/exe/rspec --pattern spec/\*\*\{,/\*/\*\*\}/\*_spec.rb
.F

Failures:

  1) Danger::DangerPlugin with Dangerfile Does something
     Failure/Error: env = Danger::EnvironmentManager.new(testing_env)

     NoMethodError:
       undefined method `title' for nil:NilClass
     # ./spec/spec_helper.rb:57:in `new'
     # ./spec/spec_helper.rb:57:in `testing_dangerfile'
     # ./spec/plugin_spec.rb:11:in `block (3 levels) in <module:Danger>'

Finished in 0.02031 seconds (files took 0.43747 seconds to load)
2 examples, 1 failure

And nobody wants that.

But looking at https://github.com/danger/danger/blob/master/spec/spec_helper.rb#L66-L69 gave me the hint that it was an erroneous template.

Now I'm getting all kinds of* green in my shell with tests passing, and it's a happy day.

(*one kind of)

notjosh commented 8 years ago

Oh, huh, now that I look at it closer, that's only causing it to swallow the error via cork and (quietly) bail on the test, and therefore skip assertions. False greens are the worst greens.

notjosh commented 8 years ago

Hmm, so I guess two issues now. I'll close this, but in case anyone stumbles over it in future, the error that was hidden was:

Could not set up API to Code Review site for Danger

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_USERNAME, DANGER_BITBUCKETCLOUD_PASSWORD

Found these keys in your ENV: HAS_JOSH_K_SEAL_OF_APPROVAL, TRAVIS_PULL_REQUEST, TRAVIS_REPO_SLUG, TRAVIS_COMMIT_RANGE, DANGER_GITHUB_API_TOKEN.

DANGER_GITHUB_API_TOKEN appears there in both sections so I'm not sure why it's upset. But I'll submit a patch over at danger/danger to get the error visible.

notjosh commented 8 years ago

Okay, the error occurs when your plugin doesn't have a git origin. To solve it, simply (even if temporarily) run:

git remote add origin git@github.com:example/foobar.git

And your tests will continue to work :)

orta commented 8 years ago

I wonder if we should add a LOC checking for that in the spec helper and billing out?

notjosh commented 7 years ago

That's a reasonable solution to it for now. I'll get to it later, if you don't first. Ideally you wouldn't need a git origin just to run tests, but that's a PR for another day.