2

I want to test javascript code from a ruby context. Specifically, I want to setup my database with ruby, query it with my javascript model, and confirm my javascript state from ruby. I want to do this without mocking.

I've tried simply loading my client libraries into a v8 context, but that causes therubyracer to choke in all sorts of ways (window not defined, userAgent not defined, etc).

Further I'm using headless browsers to test my javascript code, but they don't provide me the ruby context I need to leverage for these cases.

I think I need to load a browser (or a dom simulator) into a v8 context, but i don't what libraries are out there to do this. Maybe you have another idea?

How can I do this?

Dane O'Connor
  • 75,180
  • 37
  • 119
  • 173

1 Answers1

2

I've used capybara-webkit for this kind of task. You don't actually need to use the RSpec helpers, you can also simply create an in-memory browser instance which you can direct to your HTML/Javascript. The advantage is that it provides a evaluate_script method that can be used to interact with the browser's Javascript context (to push/receive data).

Whether or not this is applicable in your case is what kind of "ruby context" you need to be able to access from the Javascript side.

There are also some other projects you might be interested in:

Niklas B.
  • 92,950
  • 18
  • 194
  • 224