Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Ruby on Rails tests - how to make them pass? (Rspec, TDD)

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have the following tests written in the below file. I need to edit 'worker.rb' in order to get it to pass all of the tests.

This is a brain teaser my friend gave me, but I cannot figure out much. Help is much appreciated ;) !!!

worker_spec.rb



worker.rb



Test Fails Log:

....FFFFFFF

Failures:

1) Worker merging two workers should delete the loser
Failure/Error: expect { Worker.find(@loser.id) }.to raise_error(ActiveRecord::RecordNotFound)
expected ActiveRecord::RecordNotFound but nothing was raised
# ./spec/models/worker_spec.rb:35:in `block (3 levels) in <top (required)>'

2) Worker merging two workers should merge the writings together
Failure/Error: @result.writings.length.should eq 2

expected: 2
got: 1

(compared using ==)
# ./spec/models/worker_spec.rb:39:in `block (3 levels) in <top (required)>'

3) Worker merging two workers when the winner has no email should merge in the loser's email
Failure/Error: @result.email.should eq @loser.email

expected: "loser@example.com"
got: ""

(compared using ==)
# ./spec/models/worker_spec.rb:51:in `block (3 levels) in <top (required)>'

4) Worker duplicate detection should return true if the first name, last name, and email are the same
Failure/Error: @joe.duplicates?(@dupe).should be_true
NoMethodError:
undefined method `duplicates?' for #<Worker:0x007f988a283ca8>
# ./spec/models/worker_spec.rb:63:in `block (3 levels) in <top (required)>'

5) Worker duplicate detection should return false if the first name, last name, or email are different
Failure/Error: @joe.duplicates?(@tim).should be_false
NoMethodError:
undefined method `duplicates?' for #<Worker:0x007f988a37c768>
# ./spec/models/worker_spec.rb:67:in `block (3 levels) in <top (required)>'

6) Worker duplicate detection should return false if the argument is nil
Failure/Error: @joe.duplicates?(nil).should be_false
NoMethodError:
undefined method `duplicates?' for #<Worker:0x007f9889f89cc8>
# ./spec/models/worker_spec.rb:71:in `block (3 levels) in <top (required)>'

7) Worker duplicate detection should return true if the argument is self
Failure/Error: @joe.duplicates?(@joe).should be_true
NoMethodError:
undefined method `duplicates?' for #<Worker:0x007f988c003aa8>
# ./spec/models/worker_spec.rb:75:in `block (3 levels) in <top (required)>'

Finished in 0.19964 seconds
11 examples, 7 failures



Thanks for any advice you can give!!!

 
Jay Whittaker
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Update:

I added this to the model worker.rb, now have only 3 tests left to solve:
 
I do some of my very best work in water. Like this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic