views:

164

answers:

3

How would you test multi user interaction with Cucumber/webrat?

Meaning that there must be more than one user logged in. Good example would be simple chat application, where I want to send message from one user to another and check if the other user received the message.

I'd like to test at integration level, without any stubbing or mocking.

+2  A: 

I'd use Selenium RC with two separate instances controlling separate browsers. I imagine there may be other tools out there for web-based integration tests that are as useful as Selenium or even more, but, personally, I have never met one yet.

Alex Martelli
A: 

HTTP is a pull protocol, this means that users can't be notified when another performs an action. Because of this it is sufficient to simply switch users half way through your scenario. To take your chat example, here's the cucumber scenario that you would use

  Scenario: Send a message
    When I login in as "user_a"
        And I go to the chat page
        And I fill in "message" with "blah blah"
        And I press "Send"
        And I switch_user_to "user_b"
        And I go to the chat page
    Then I should see "blah blah"

Even if your page is sending polling requests via ajax to get the latest messages it is still sending a request. In that case you could test the ajax call by simply doing a step where user_b calls the url that the ajax request is calling.

opsb
there is [an entire field](http://en.wikipedia.org/wiki/Comet_%28programming%29) about how to avoid polling ajax calls for this type of thing, but the question asked did not deal with those. The question was how to use two session in the same test.
John F. Miller
+1  A: 

I know how this should be done, I just cannot find the right place to do it:

You need to create a second Webrat::Session instance the original webrat_session that you get for free can be one party, while the new one can be the other. I might make two new named sessions just so I could name them.

alice = Webrat::Session.new #I think I have to hook this into merb and I don't know how
bob = Webrat::Session.new

alice.visit url(:chat)
bob.visit url(:chat)
alice.fill_in('chat', 'Hi, bob')
bob.visit url(:chat) #simulate poling
bob.responce.body should_contain "alice: Hi, bob"
John F. Miller