Skip to content

Instantly share code, notes, and snippets.

@randalmaile
Last active December 30, 2015 16:08
Show Gist options
  • Save randalmaile/7852319 to your computer and use it in GitHub Desktop.
Save randalmaile/7852319 to your computer and use it in GitHub Desktop.
Debugging Code Checkpoint
"Hello World"
"Hello Bob"
```Bloc Output
INCOMPLETE METHOD
```
**hello returns a full greeting for Abraham Lincoln**
```
ArgumentError
wrong number of arguments (2 for 0)
exercise.rb:1:in `hello'
exercise.rb:7:in `block (2 levels) in <top (required)>'
```
**hello returns a full greeting for George Washington**
```
ArgumentError
wrong number of arguments (2 for 0)
exercise.rb:1:in `hello'
exercise.rb:10:in `block (2 levels) in <top (required)>'
```
```Bloc Output
WRONG # OF ARGUMENTS
```
**hello returns a full greeting for Abraham Lincoln**
```
ArgumentError
wrong number of arguments (2 for 3)
exercise.rb:1:in `hello'
exercise.rb:7:in `block (2 levels) in <top (required)>'
```
**hello returns a full greeting for George Washington**
```
ArgumentError
wrong number of arguments (2 for 3)
exercise.rb:1:in `hello'
exercise.rb:10:in `block (2 levels) in <top (required)>'
```
```Bloc Output
CORRECT METHOD
```
hello returns a full greeting for Abraham Lincoln
hello returns a full greeting for George Washington
```Bloc Output
NO NAME ERROR
```
**hello should return 'Hello first name last name'**
```
NoMethodError
undefined method `hello' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f53c92185d0>
exercise_spec.rb:5:in `block (2 levels) in <top (required)>'
```
```Bloc Output
NO NAME ERROR - CORRECTED
```
hello should return 'Hello first name last name'
```Bloc Output
TYPE ERROR
```
**add returns a string with 1 and 2 added**
```
TypeError
String can't be coerced into Fixnum
exercise.rb:2:in `+'
exercise.rb:2:in `add'
exercise.rb:9:in `block (2 levels) in <top (required)>'
```
**add returns a string with 5 and 7 added**
```
TypeError
String can't be coerced into Fixnum
exercise.rb:2:in `+'
exercise.rb:2:in `add'
exercise.rb:12:in `block (2 levels) in <top (required)>'
```
```Bloc Output
TYPE ERROR - CORRECTED
```
add returns a string with 1 and 2 added
add returns a string with 5 and 7 added
```Bloc Output
UNEXPECTED END
```
exercise_spec.rb:2:in `require': exercise.rb:8: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError)
from exercise_spec.rb:2:in `<top (required)>'
```Bloc Output
UNEXPECTED END - CORRECTED
```
hello should return 'Hello World'
# NO METHOD ERROR
def hello(name)
p "Hello #{name}"
end
describe "hello" do
it "should return 'Hello World' when passed 'World'" do
hello("World").should eq("Hello World")
end
it "should return 'Hello Bob' when passed 'Bob'" do
hello("Bob").should eq("Hello Bob")
end
end
# WRONG NUMBER OF ARGUMENTS
def hello
""
end
describe "hello" do
it "returns a full greeting for Abraham Lincoln" do
hello("Abraham", "Lincoln").should eq("Hello Abraham Lincoln")
end
it "returns a full greeting for George Washington" do
hello("George", "Washington").should eq("Hello George Washington")
end
end
# WROTE OUT THE METHOD w/ WRONG NUM OF ARGUMENTS
def hello(fist, last, middle)
"Hello #{first} #{last}"
end
describe "hello" do
it "returns a full greeting for Abraham Lincoln" do
hello("Abraham", "Lincoln").should eq("Hello Abraham Lincoln")
end
it "returns a full greeting for George Washington" do
hello("George", "Washington").should eq("Hello George Washington")
end
end
# CORRECTED THE METHOD
def hello(first, last)
"Hello #{first} #{last}"
end
describe "hello" do
it "returns a full greeting for Abraham Lincoln" do
hello("Abraham", "Lincoln").should eq("Hello Abraham Lincoln")
end
it "returns a full greeting for George Washington" do
hello("George", "Washington").should eq("Hello George Washington")
end
end
### NO NAME ERROR ###
#Error
def hello(first, last)
"Hello #{firs} #{last}"
end
describe "hello" do
it "should return 'Hello first name last name'" do
hello("Steve", "Jobs").should eq("Hello Steve Jobs")
end
end
#corrected
def hello(first, last)
"Hello #{first} #{last}"
end
describe "hello" do
it "should return 'Hello first name last name'" do
hello("Steve", "Jobs").should eq("Hello Steve Jobs")
end
end
## TYPE ERROR
# ERROR CODE
def add(a,b)
a + " plus " + b
end
describe "add" do
it "returns a string with 1 and 2 added" do
add(1,2).should eq("1 + 2 = 3")
end
it "returns a string with 5 and 7 added" do
add(5,7).should eq("5 + 7 = 12")
end
end
# CORRECTED CODE
def add(a,b)
"#{a} + #{b} = #{a+b}"
end
describe "add" do
it "returns a string with 1 and 2 added" do
add(1,2).should eq("1 + 2 = 3")
end
it "returns a string with 5 and 7 added" do
add(5,7).should eq("5 + 7 = 12")
end
end
## UNEXPECTED END
# ERROR CODE
def hello
"Hello World"
describe "hello" do
it "should return 'Hello World'" do
hello.should eq("Hello World")
end
end
# CORRECTED CODE
def hello
"Hello World"
end
describe "hello" do
it "should return 'Hello World'" do
hello.should eq("Hello World")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment