Skip to content

Instantly share code, notes, and snippets.

@JoshCheek
Created September 22, 2016 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoshCheek/9c00965885785daf03a7015799ee5722 to your computer and use it in GitHub Desktop.
Save JoshCheek/9c00965885785daf03a7015799ee5722 to your computer and use it in GitHub Desktop.
Contributing To Open Source - LA Fullstack Meetup Notes

Submitting a pull request

For the LA Fullstack meetup.

Fork the repository

This will give you a copy on your own account, that you can do anything you want with (assuming the license permits it).

Clone your fork

This will give you a copy of your fork on your machine. Make sure you're in the parent directory (folder).

$ git clone git@github.com:JoshCheek/erroneous_creatures.git
$ cd erroneous_creatures

Install any dependencies

For a Ruby project, this will usually be $ bundle install, for a JavaScript project, it will usually be $ npm install.

For us on this project, it will be:

$ gem install minitest

Run the tests

On a real project, you're trying to make sure that everything works before you start working on it. In ours, it will identify things that are broken.

$ ruby centaur_test.rb

Write a failing test

On a real project, you will need to write your own test, but on ours, you can use your own failing test.

Pick one of the ones that fails, eg test_it_has_excellent_bow_skills, then run just that one:

$ ruby centaur_test.rb -n test_it_has_excellent_bow_skills

When I work in RSpec, I use tags to do this, for JavaScript, mocha has a .focus method that you can use to choose the test you want.

Fix the failing test

Analyze and fix the failing test. Debugging is its own topic, but the general approach is to figure out what's going on. Start by reading the test name, and understanding what the test is trying to say in English. Then consider the tests around it, the body, etc. Is it different than was expected? Did something happen that shouldn't have? Did something not happen that should have? etc. Feedback is the name of the game here.

In our case, we can see that it's exploding on @crankiness += 1, and we see there's an attr_accessor for crankiness. It's blowing up because nil doesn't have a + method. Since we're adding 1 to it, it probably should have been an integer. Where should its value have come from? Probably it should have been set when the object was initialized. Based on how its being used, it's a counter, so it should probably start at a count of zero. So, we go to initialize and set it to 0.

class Centaur
  def initialize(name, breed, standing=true, laying=false, sleeping=false)
    # ...
    @crankiness = 0
  end
  # ...
end

We run our test again and see it pass.

$ ruby centaur_test.rb -n test_it_has_excellent_bow_skills

Commit the changes

First look to make sure we changed what we think we did:

$ git status
...
Changes not staged for commit:
modified:   centaur.rb

Cool. If you have multiple files changed, diff them one at a time:

$ git diff centaur.rb
git diff centaur.rb
diff --git a/centaur.rb b/centaur.rb
index e7b4615..2930000 100644
--- a/centaur.rb
+++ b/centaur.rb
@@ -9,6 +9,7 @@ class Centaur
     @standing = standing
     @laying = laying
     @sleeping = sleeping
+    @crankiness = 0
   end

   def shoot

Looks good, lets add that:

$ git add centaur.rb

And verify it worked:

$ git status
Changes to be committed:
modified:   centaur.rb

So now it's added to the staging area. If we had more files, we would diff them and add them one at a time, until everything was staged that we wanted to submit.

Once staged, we commit:

$ git commit -m 'Initialize Centaur crankiness'

And do another status to make sure that it worked:

$ git status
...
Your branch is ahead of 'origin/master' by 1 commit.

Push your commit to your fork

This will put your code on your copy, up on Github.

$ git push

Send the pull request

This will tell me that you think I should bring your change into my repository on Github.

Go to your copy on Github, you should see your change, and a big green button that says "Compare & Pull", click that button. Add a name and description of the change, and click "Create pull request".

At this point, a new pull request will be created in my repo https://github.com/JoshCheek/erroneous_creatures/pulls.

I can look over your changes, comment on them, and ask you to make changes, or decide that I like it and merge it into my code, or that I don't want to merge the code and close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment