###NoMethodError
NoMethodError: undefined method `hello` for main:Object
Means that we tried to invoke the hello method, which has yet to be defined
###Wrong Number of Arguments - ArgumentError
ArgumentError
wrong number of arguments (2 for 1)
exercise.rb:1:in `hello'
exercise_spec.rb:5:in 'block (2 levels) in <top (required)>'
This tells us that the method hello is being invoked with 2 arguments but the method definition only takes 1
###NameError
NameError
undefined local variable or method `firs' for #<RSpec::Core::ExampleGroup::Nested_1:0x007f30f9b42360>
exercise.rb:2:in `hello'
exercise_spec.rb:5:in 'block (2 levels) in <top (required)>'
Telling us that there is most likely a typo in one of our variables or the variable is undefined
###TypeError
def add(a,b)
a + " + " + b + " = " + (a + b)
endSpecs:
describe "add" do
it "returns a string with 1 and 2 added" do
expect( add(1,2) ).to eq("1 + 2 = 3")
end
it "returns a string with 5 and 7 added" do
expect( add(5,7) ).to eq("5 + 7 = 12")
end
endError given:
TypeError
String can't be coerced into Fixnum
exercise.rb:2:in `+'
exercise.rb:2:in `add'
exercise_spec.rb:5:in `block (2 levels) in <top (required)>'
Tells us that the string can't be converted into a number, try using string interpolation such as:
def add(a,b)
"#{a} + #{b} = #{a + b}"
end###syntax error
def hello
"Hello World"Error given
exercise_spec.rb:2:in `require': exercise.rb:2: syntax error, unexpected end-of-input, expecting keyword_end (SyntaxError) from exercise_spec.rb:2:in `<top (required)>'
syntax error's tells us we are missing or have an extra keyword, or character somewhere. In this case we are missing end in our hello method.