Skip to content
This repository has been archived by the owner on Jun 20, 2022. It is now read-only.

HTTP stub helpers #80

Merged
merged 3 commits into from
Mar 13, 2015
Merged

HTTP stub helpers #80

merged 3 commits into from
Mar 13, 2015

Conversation

pengwynn
Copy link
Collaborator

Inspired by Octokit.rb's stub helpers, this is a work-in-progress proof-of-concept for removing some noise from our tests. We can have our 🍰 and eat it, too, because you can always do the more verbose approach if you need to.

Before we get too far, I wanted to see what @jingweno thinks of the approach.

/cc @obsc @dhruvsinghal @dhs252

@owenthereal
Copy link
Contributor

@pengwynn 👍 Good refactoring! So much DRYer.

stubRequest(t, "GET", path, fixture, params)
}

func stubRequest(t *testing.T, method string, path string, fixture string, params map[string]string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could prob. pass a func at the last for assertion or optional manipulation as well:

func stubGet(t *testing.T, path, fixture string, params map[string]string, f func(w http.ResponseWriter, r *http.Request)) {
}


func stubRequest(t *testing.T, method string, path string, fixture string, params map[string]string, f func(w http.ResponseWriter, r *http.Request)) {
  ...

  mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
       if f != nil {
          f(w, r)
       } 
  }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good call. I like that idea.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like that idea as well.

Looking through the code again, there's only a single place where we respond with a fixture and we need other assertions (users_test.go). Other locations with asserts (gists_test.go) respond with an arbitrary string (in this case "hello").
It might be a better idea to pass in the full response rather than just the fixture name.

pengwynn added a commit that referenced this pull request Mar 13, 2015
@pengwynn pengwynn merged commit 3dab8a3 into master Mar 13, 2015
@pengwynn pengwynn deleted the http-stub-helpers branch March 13, 2015 15:44
obsc added a commit that referenced this pull request Mar 13, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants