Guest User

Untitled

a guest
Sep 9th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. Connecting to MySQL DB in Ruby Rspec
  2. 1)... #skipped irrelevant info
  3. Failure/Error: graph.read_db('example1')
  4. Not connected to any DB. #error msg
  5. #./prim.rb:135:in 'read_db'
  6. #./prim_spec.rb:171:in 'block (2 levels) in <top (required)>'
  7.  
  8. describe PGraph, "online" do
  9. before (:all) do
  10. ActiveRecord::Base.establish_connection(
  11. :adapter => "mysql2",
  12. :host => "localhost",
  13. :username => "root",
  14. :password => "xxxxx",
  15. :database => "rubytasks" )
  16. #the exact same statement works perfectly when running the program itself, but fails in RSpec
  17. end
  18. before (:each) do
  19. @graph = PGraph.new
  20. end
  21.  
  22. it "should correctly retrieve data from database" do
  23. @graph.read_db('example1') #line 171
  24. #business part goes here
  25. end
  26. end
  27.  
  28. class PGraph
  29. def read_db(graphID)
  30. #the error which is raised (line 135):
  31. raise "Not connected to any DB." unless ActiveRecord::Base.connected?
  32. #reading goes here
  33. end
  34. end
Add Comment
Please, Sign In to add comment