stepful / cyperful

Interactive system testing UI for capybara

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add Rspec compatibility

wyattades opened this issue · comments

Context: Right now we only support MiniTest, because that's what I use for my projects :)

Tasks:

  • split into separate imports: cyperful/minitest & cyperful/rspec
  • inject into Rspec setup/teardown flow (easy)
  • parse rspec test files (hard)
    • describe, it, context, etc.
  • add tracing on all Rspec commands (hard)
    • e.g. expect(page).to have_content("foo")
    • This was pretty easy on MiniTest because we only needed to look at methods starting with assert_, and all tests were direct methods of a ActiveSupport::TestClass class

UPDATE: I am actively working on this, a PoC should be ready soonish.

* add tracing on all Rspec commands (hard)
  * e.g. `expect(page).to have_content("foo")`
  * This was pretty easy on MiniTest because we only needed to look at methods starting with `assert_`, and all tests were direct methods of a `ActiveSupport::TestClass` class

If I understood your code correctly, that part should be as easy as

@step_at_methods =
    Capybara::Session::DSL_METHODS.to_set +
    [:expect] - 
    %i[ html body current_url etc ]

(there is an older should_... syntax, but that has been deprecated and hidden behind a feature flag years ago, so I don't think you need to support it)

The only problem I see is something like

def accept_cookies
  expect(page).to have_css('.cookie-banner')
  click_link_or_button('Accept')
end

it 'tracks the user after they accept cookies' do
  # visit the page
  accept_cookies
  # expect tracking to happen
end

I'm not sure whether this would show up as an expectation, especially if the method is defined in a helper module in another file. Does Minitest have a similar problem?

The only problem I see is something like

def accept_cookies
  expect(page).to have_css('.cookie-banner')
  click_link_or_button('Accept')
end

it 'tracks the user after they accept cookies' do
  # visit the page
  accept_cookies
  # expect tracking to happen
end

I'm not sure whether this would show up as an expectation, especially if the method is defined in a helper module in another file. Does Minitest have a similar problem?

you're right, my naive static analyzer doesn't parse custom methods like that as "steps". It looks at the AST of the test code, but doesn't "follow" method definitions. Maybe I could try this out in the future.

There is currently a manual workaround: Cyperful.add_step_at_methods(:accept_cookies).

Released the initial support for RSpec under v0.2.0. Open to feedback and bug reports, please let me know by opening new issues!