简体   繁体   中英

Unable to run ruby spec tests of rails app backed by neo4j

I have recently inherited a rails app backed by neo4j instead of postgres.

When I try to run the spec tests like this

NEO4J_TYPE=bolt NEO4J_URL="bolt://localhost" bundle exec rake spec

I get

/Users/user1/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/faraday-0.9.2/lib/faraday/adapter/net_http.rb:66:in `create_request': undefined method `request_uri' for #<URI::Generic bolt://localhost> (NoMethodError)

I also tried

NEO4J_TYPE=bolt NEO4J_URL="bolt://localhost:7687" bundle exec rake spec

I read http://neo4jrb.readthedocs.io/en/7.1.x/Setup.html and http://neo4jrb.readthedocs.io/en/9.0.x/Testing.html

but haven't found a solution yet.

Some things I've done:

brew install neo4j. # also installed java 8 with brew
rake neo4j:config[test,7575]
brew services stop neo4j
brew services start neo4j

$ cypher-shell -a bolt://localhost
Connected to Neo4j 3.3.0 at bolt://localhost:7687.
Type :help for a list of available commands or :exit to exit the shell.
Note that Cypher queries must end with a semicolon.
neo4j> 
Interrupted (Note that Cypher queries must end with a semicolon. Type :exit to exit the shell.)
neo4j> 

This has to do with how you're defining the URL. You're using the bolt scheme, so URI doesn't know what type of URI it is and thus does provides a generic URI instance.

bolt_uri = URI.parse("bolt://localhost") #=> #<URI::Generic bolt://localhost>
bolt_uri.request_uri #=> Raises NoMethodError

http_uri = URI.parse("http://localhost") #=> #<URI::HTTP http://localhost>
http_uri.request_uri #=> "/"

Essentially, because the interface is over HTTP and being passed to Faraday (an HTTP client), the URL should be defined as NEO4J_URL="http://localhost" .

In regards to Daniel's answer, the gem should allow for bolt:// as the URL (see the Setup documentation that joshsverns linked to). The schema is figured out here:

https://github.com/neo4jrb/neo4j/blob/master/lib/neo4j/railtie.rb#L98

On the line above it calls scheme which gets the bolt out of the URL. Also, you can see from there that the NEO4J_TYPE environment variable is ignored when the NEO4J_URL is specified.

All that said, the error that joshsverns is getting definitely seems like it's trying to use Faraday, which should only be used for the HTTP adaptor. I'd need more of a backtrace to understand the path that is being taken.

Though the bolt implementation is not quite as mature as I'd like it to be. I've generally been recommending that people use HTTP for now (though I'm always happy to have people testing bolt).

Also, minor note: You linked to http://neo4jrb.readthedocs.io/en/7.1.x/Setup.html From the URL that's the documentation for 7.1.x which is not the latest version of the gem (though I'm not sure what version you are using)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM