Why doesn't the test work?

require 'rspec' class Test attr_accessor :name def girl puts "Hello #{name}" end end describe "Hello" do it "Hello Mari" do name1=Test.new name1.name="Mari" name1.girl=="Hello Mari" end end 

    1 answer 1

    Beginners may be advised to refer to the http://rspec.info documentation more often.

    It doesn't work because tests write a little differently.

     name1 = Test.new name1.name = 'Mari' expect(name1.girl).to eq('Hello Mari') 
    • I agree, but until you find a specific answer there, it will take a long time, and I thank you for the answer. - Sad
    • there are many examples - Nik
    • Your code also does not work, I checked it ( - Sad
    • Here is the Hello Mari F Failures code error: 1) Hello Hello Mari Failure / Error: expect (name1.girl) .to eq ("Hello Mari") expected: "Hello Mari" got: nil (compared using ==) # ./ ww.rb: 14: in `block (2 levels) in <top (required)> 'Finished in 0.04207 seconds (files did 0.34031 seconds to load) 1 example, 1 failure Failed examples: rspec ./ww.rb:11 # Hello Hello Mari - Sad
    • Not noticed in your method uses puts . To return a string, you can simply write "Hello #{name}" (without puts). And if you want to test the standard output, this link stackoverflow.com/questions/17709317/how-to-test-puts-in-rspec/… can help. - Nik