Giter Club home page Giter Club logo

ruby-method-drills's Introduction

Ruby Method Drills

Current Labs Version Issues Count

Overview

Write code in each starter code file to pass the tests in the spec folder!

Objectives

This will be way more practice with Ruby methods and test driven development - and a great opportunity to explore some new tactics!

Setup

Clone this repo on GitHub.

git clone https://github.com/SF-WDI-LABS/ruby-method-drills
cd ruby-method-drills

The files you'll work on are:

  1. arguments.rb -- (test file is argument_spec.rb)

  2. strings.rb -- (test file is string_spec.rb)

  3. numbers.rb -- (test file is number_spec.rb)

  4. hashes.rb -- (test file is hash_spec.rb)

  5. iterators.rb -- (test file is iterator_spec.rb)

Testing

We'll use a tool called rspec to outline our objectives AND test our code as we go... hooray for Test Driven Development (TDD)!

rspec is available as a Ruby gem, so start in your terminal by running the command:

    gem install rspec

You might get an error here, but we believe in you. Fix it.

Test Driven Development -- "Red, Green, Refactor"

Take a look at one of the "spec" files in the spec/ folder. These are the tests that we want to make pass.

To run all the tests type the following in the command line:

    rspec
    # or run a specific spec file
    rspec spec/argument_spec.rb

You should see this as part of your output:

Failures:

  1) #say_hello returns 'hello'
     Failure/Error: expect( say_hello ).to eq "hello"

     NameError:
       undefined local variable or method `say_hello' for #<RSpec::ExampleGroups::SayHello:0x007f9ef3a9cc68>
     # ./spec/argument_spec.rb:14:in `block (2 levels) in <top (required)>'

Congrats!

  • The first tests are failing. We're seeing RED.
  • Now we need to write code (in the starter code directory) to pass the tests and turn them GREEN.
  • When a test passes, we're ready to stop and REFACTOR!

Rspec Tips

  • Pay close attention to the rspec output in your terminal.
  • Run your tests frequently and read the output carefully.
  • BE VERY CAREFUL to use the correct function name.
  • To limit your test output, consider filtering tests by method name with the -e flag:
    rspec spec/argument_spec.rb -e get_fruit

Ruby Tips

When in doubt, test your code in the ruby REPL (irb or pry).

(This is similar to running the node repl by typing node).

When you want to quit irb or pry, type and enter quit.

Inside pry, you can "hang a dot" and hit tab twice to see available methods:

    2.1.2 :001 > "string". # hang a dot and hit tab twice!
    # Display all 148 possibilities? (y or n)
    #                               "".match
    # "".__id__                      "".method
    # "".__send__                    "".methods
    # "".ascii_only?                 "".next
    # "".b                           "".next!
    # "".between?                    "".nil?
    # "".bytes                       "".object_id
    # "".bytesize                    "".oct
    # ...

Another handy trick is to load your Ruby file so that you can manually test your functions.

Make sure you're in the correct directory, then in pry type:

    2.1.2 :002 > load "./starter-code/arguments.rb"
    2.1.2 :003 > say_hello

(Re-load your file after you make changes.)

You can also run a ruby file from the command line by typing:

    ruby starter-code/arguments.rb

ruby-method-drills's People

Contributors

nuranned avatar bgveenstra avatar nathanallen avatar mnfmnfm avatar jeanmw avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.