Contributing to Open Source

With Github!

Here's the thing...





It's always better to show than tell




Open source

What is open source?

  • "Open source refers to a program in which the source code is available to the general public for use and/or modification from its original design."

  • "Typically created as a collaborative effort in which programmers improve upon the code and share the changes within the community."

  • "A response to proprietary software owned by corporations."

Thanks Wikipedia!

Why Open Source?

  • Collaborative code
  • Community problem solving
  • Everyone can use and contribute




Git

Why is Get Spelled weird?

Git refers to a version control system that keeps track of revisions of your code and lets multiple people work on the same project at once without stepping on each other's toes.

"Hey, all that work that you did last night? I accidentally uploaded everything to the server, and now all your changes are gone."

How Do I learn It?

Commands to Keep In mind

 git clone <repo> <location>
 git add [-u] <files>
 git commit [-m <message>]
 git push <reponame> <branchname>


 git pull
 git diff
 git checkout -b <reponame>




Github

Where is it


What A project looks like

Sidebar

Issues

  • Issues act as a to-do list for a project
    • They can be enhancements, bugs, suggestions
    • Really it's whatever you want.
  • People can argue and haggle about specific issues
  • Issues can be assigned to people and can be related to milestones.
  • Issues can be related to commits
    • So you can see the commit that solved that issue
  • Issues can be closed with a commit message
get commit -m "adds feature x, closes #4"

Pull-Requests

A pull request is a way of asking the original developer, "Hey, is this code good enough to be added in?"

  • Pull requests make it so not just anyone can contribute without peer review.
  • Let's you comment more about the code and can be related to issues.

Forking

Forking

Forking takes a copy of a project and puts it into your repository.

  • Helps to not step over ANYTHING.
  • Keeps individual repos nice and clean.




Unit Testing

Who watches the watchmen?


Unit testing is really important.

Really.

I can't stress this enough.


  • Unit testing keeps you from accidentally breaking code somewhere else
  • Allows others to quickly validate your code 
  • Be careful to not go too far down this rabbit hole (writing tests for your tests)

So what is it?

Unit tests are functions that you run to test:

  • That methods return what you expect them to return.
  • That things break where you want them to break.
  • The types of things returned are what you expect.

...and more!

Testing in ruby

Getting started is really easy
require '{the_class_you_are_testing}'
require 'test/unit'
Then make a class that extends the unit test class
class TestEmailReader < Test::Unit::TestCase
end
Now you can start using all your assertions!

Big list of assertions to use

True if...
assert( boolean, [message] )
True if expected == actual
assert_equal( expected, actual, [message] )
assert_not_equal( expected, actual, [message] ) 
True if string =~ pattern
assert_match( pattern, string, [message] )
assert_no_match( pattern, string, [message] )
True if object == nil
assert_nil( object, [message] )
assert_not_nil( object, [message] )

Some more!

True if (actual_float - expected_float).abs <= delta
assert_in_delta( expected_float, actual_float, delta, [message] )
True if object.class == class
assert_instance_of( class, object, [message] )
True if object.kind_of?(class)
assert_kind_of( class, object, [message] )
True if actual.equal?( expected ).
assert_same( expected, actual, [message])
assert_not_same( expected, actual, [message] )

I swear we're almost done


True if the block raises (or doesn't) one of the listed exceptions.
assert_raise( Exception,... ) {block}
assert_nothing_raised( Exception,...) {block}
True if the block throws (or doesn't) the expected_symbol.
assert_throws( expected_symbol, [message] ) {block}
assert_nothing_thrown( [message] ) {block}
True if the object can respond to the given method.
assert_respond_to( object, method, [message] )
True if the block throws (or doesn't) the expected_symbol.
assert_throws( expected_symbol, [message] ) {block}
assert_nothing_thrown( [message] ) {block}

One more...

True if the method sent to the object with the given arguments return true.
assert_send( send_array, [message] ) 
Compares the two objects with the given operator, passes if true
assert_operator( object1, operator, object2, [message] )

Source 

Workflow

  1. Find a project
  2. Look through the issues and pick one
  3. Fork the project
  4. Clone it from your repo
  5. Do code-y things
  6. Run the unit tests
  7. Commit and push your code changes
  8. Submit  a pull-request to the original project

Fork up the sample project at 

Find me on things


Twitter

LinkedIn: 

Fork me up on Github

Good ol' email:

Open Source

By Kevin Baugh

Open Source

  • 657