Testing Morris.js graphs with rspec

199 Views Asked by At

I use Morris.js for graphs in ruby on rails and find it very useful. However, I am not sure how to test the graphs using feature specs in rspec with capybara. At the very least I would like to test the following

  • the graph is displaying on the page
  • the right type of graph e.g. a line graph
  • there is some data being plotted, e.g. check there are two lines in the graph.

How do you do this?

1

There are 1 best solutions below

0
On BEST ANSWER

I can now answer the first two parts of the question. If the graph is working, the javascript code inserts an html svg element in the page. So using a feature spec with js: true, you can test for this with: page.should have_css 'svg'

If you have different graphs on the same page, you can wrap each in a div and test with something like: within :css, 'div#first_chart' do page.should have_css 'svg' end This does not exactly tell you that you have the right type of Morris graph in there, but should suffice for most purposes.

I still do not know how to check more detailed features like the number of lines appearing on a graph.