Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connecting to MySQL DB in Ruby Rspec
- 1)... #skipped irrelevant info
- Failure/Error: graph.read_db('example1')
- Not connected to any DB. #error msg
- #./prim.rb:135:in 'read_db'
- #./prim_spec.rb:171:in 'block (2 levels) in <top (required)>'
- describe PGraph, "online" do
- before (:all) do
- ActiveRecord::Base.establish_connection(
- :adapter => "mysql2",
- :host => "localhost",
- :username => "root",
- :password => "xxxxx",
- :database => "rubytasks" )
- #the exact same statement works perfectly when running the program itself, but fails in RSpec
- end
- before (:each) do
- @graph = PGraph.new
- end
- it "should correctly retrieve data from database" do
- @graph.read_db('example1') #line 171
- #business part goes here
- end
- end
- class PGraph
- def read_db(graphID)
- #the error which is raised (line 135):
- raise "Not connected to any DB." unless ActiveRecord::Base.connected?
- #reading goes here
- end
- end
Add Comment
Please, Sign In to add comment