Capybara / Poltergeist Internals: Running the Server in a Separate Process/Environment - capybara

I'm attempting to use Capybara and Poltergeist to automate taking screenshots of my Rails application. I already have this sort of working, and I've integrated the functionality with Rails' asset pipeline. (See this question for more on that.)
While testing my current setup, however, I've noticed lots of weird issues that seem to be caused by Capybara and my application running in the same process. Is there a way to make Capybara run its server in a separate process, in a different environment?

You can make Capybara run against an external server by following the directions in the "Calling remote servers" section of the README. I think your best bet would be to fork an external server yourself before calling Capybara (e.g., in a rake task or a hook in your testing framework) and then treat it as a remote server in Capybara.

Related

Rails 5.1 Running System Tests on Puma?

I was wondering if there was a way to use the Puma server (Rails default) JUST on the new Rails 5.1 system tests?
Right now on all our projects we use tiny_tds, but I was trying to experiment with 5.1 system tests with Capybara/Selenium but it fails of course because I do not have Puma installed/running.
I took a look through the documentation and didn't see anything about declaring what type of server you want to use. Were connecting to a SQL Server database so I don't know if Puma is able to do that (And that's probably why were using tiny_tds in the first place).
You're confusing database adapters and rack web servers which are very different things.
Puma (like Webrick, Thin, Unicorn etc) is a general purpose Rack web server. It sits and waits for incoming requests from vistors and dispatches them to an application (like a Rails app) by calling it with a hash containing the environment and request. The application returns an array containing the response. The server sends it back to the visitor.
tiny_tds on the other hand is a database adapter. Its used to connect the application to the database. The web server is almost completly oblivious to how the application creates a response from the request. This includes whatever databases are used.
In Rails 5 most servers don't require configuration. You just add the gem to the gemfile and run bundle install and they plug themselves in. There in no seperate installation step.
That was not the case earlier which is why Webrick - a server with the only real merit being that it does not require configuration was the default. It is now Puma which unlike Webrick is suited for production.
Using different servers in different environments is not a good idea since it violates the idea of dev/prod parity. Your dev & test environment should be as close as possible to what you are deploying to so that you can catch bugs before they end up in production. This means you should be running the same server, same database etc.
Running a seperate test server for different parts of your test suite sounds like a true fools errand - if its even possible without hacking the framework to bits.
For SQL Server there is activerecord-sqlserver-adapter which can use tiny_tds as a backend.

Cucumber failing in chrome with "Retry later" message

I'm trying to run my cucumber tests and they seem to stop randomly. A new page is visited but nothing renders on the page except Retry later as in the following screenshot.
I'm on OS X 10.9.3, Chrome 35.0.1916.114, and running with bundle exec cucumber. It's happening in and Firefox also if I change the javascript driver.
The problem was not with Chrome, Cucumber, or Capybara. It was with Rack::Attack. 127.0.0.1 was whitelisted but according to this github issue
it wasn't whitelisting ipv6 and transitional loopback ip addresses
To simplify things I just moved Rack Attack to be production only.
tl;dr
Rack::Attack was to blame. Unless you need it in your test environment, just make the gem production only.

Javascript not working in production: Nginx, Passenger, Rails on Ubuntu Server (Node.js?)

Do I need to install/config Node.js to get Javascript running?
Is this the simplest solution, seeing that my site has really low traffic?
Javascript doesn't seem to work for me but only in production for a site I am running. The site is setup on the latest version of Ubuntu Server, with Nginx and Passenger (it's a Ruby on Rails app). The site runs great and fast for the past few months, but Javascripts (in particular, things like Twitter Bootstrap's tooltip, etc.) don't run on this production server although they work in my testing/dev environments.
My thoughts are that Javascript is broken b/c I need to install/configure Node.js? I've seen Node.js mentioned in some deployment setup guides but can't find detailed info into if this is necessary.
My site is very low traffic (maybe 3-5 users at any time) for a small company website. The only reason I needed to setup my own web server is that I needed to run the app on the private company network to access certain resources.
By default your js/css don't compiled. You should precompile them.
You can run "bundle exec rake assets:precompile" on your computer and deploy compiled code to the server. Instead node.js you can use therubyracer gem.
For more information read rails guide

Is the deafult server (e.g., Webrick) used when running tests in rails?

when running functional and integration tests for a rails app which rails server is used during the execution of the tests? Is the default rails server used or not? Thanks in advance.
Rails' built-in functional and integration tests run with mocked web requests, so there is no web server serving the requests. (see lib/action_controller/test_case.rb in actionpack)
Some Rails testing frameworks (notably Capybara) use real rack servers when running (Capybara defaults to using Thin)

Testing Rails+Webhooks with Cucumber

I'm trying to integrate my rails application with an external service. I'm using Cucumber to do integration testing and I'd don't want to mock out the external service at times. When I get webhooks from this service, they are routed to apache running my development environment. This would be easy to fix if I could figure out how to fixate my cucumber rails process on a particular port or how to proxy to it.
Basically, how do I get external webhooks (POSTs) routed to my cucumber rails process while it's running?
It appears that this is possible with Selenium as it starts a webserver on a configurable port.
I contacted the author of this blog post and he confirmed that he was using Selenium configured on the port he forwarded with localtunnel.

Resources