Difference between Mechanize and Capybara (with webmock/webkit/selenium) - ruby-on-rails

Having read tons of documentation on the above, I am a bit confused: is there anything useful that Mechanize can do that Capybara (with webmock/webkit/selenium) cannot?

Looks like Capybara is more frequently used(http://www.techwars.io/fight/capybara/mechanize/) overall which could mean more community support.
Also, it seems that you can not test remotes with just the basic Capybara, and can with Mechanize, as it has been made a Capybara gem extension here: https://github.com/jeroenvandijk/capybara-mechanize.

Related

Capybara vs Page Object

I'm currently using Cucumber and Ruby Page Object for testing my Ruby on Rails website.
I'm trying to understand Capybara and decide if I should add it to the mix, or maybe replace Page Object with it.
I'd appreciate if somebody provides more insights into benefits of using Capybara when compared to Page Object, and does it make sense to use them together?
Thanks
You cannot use Cheezy's page-object gem with Capybara.
The page-object gem only supports Watir-Webdriver and Selenium-WebDriver. It does not support Capybara.
Capybara, Watir and Selenium are for driving browsers while page-object is for modelling your pages. If you switch to Capybara, you would need to pick a different page-object library such as SitePrism. Switching would mean you either need to support two completely separate stacks or re-write your existing tests.

Testing Rails app with RSpec and Capybara

In testing my rails app (using RSpec and Capybara) I am having troubles testing AngularJS functions (from the Users point of view). Can I not test with only RSpec and Capybara or do I also need something like protractor?
any help would be great! thank you!
You could test with Capybara, so long as you use a driver that supports javascript, such as Selenium or Poltergeist - see https://github.com/jnicklas/capybara#drivers
However, although I'm not an AngularJS user, I do know that it's designed to be testable, and I imagine you'd be much better off using a tool specifically for javascript testing, rather than capybara.
As long as angular provides it's own methods and functionalities you should separate the testing suite into two. The first one, rspec, capybara and rails will be testing just the non-angular pages.
Second one, using a tool like jasmine should be testing the angular behaviour. Both combined provides good coverage of the application.
https://docs.angularjs.org/guide/unit-testing

Is Feature/Scenerio a replacement for Describe/It?

I've been following the Ruby on Rails Tutorial. The author uses Rspec/Capybara's Describe/It for the whole tutorial. But recently I've seen people using Feature/Scenerio instead. I wonder if Feature/Scenerio is a replacement of Describe/It or something that is used together? If it is a replacement, is there any reason of prefer it over Describe/It?
The same question came up to me lately too. And I went to Capybara's github page to read more about it (search for scenario). Apparently feature, scenario and background are just aliases to make acceptance tests more readable. And I guess that's for legacy reasons -- cucumber uses those keywords. Therefore by aliasing them, capybara acceptance specs read more like traditional cucumber specs.
So no, feature/scenario/background are not a replacement of describe/it/before. As a group of methods, it is only an alternative for acceptance specs. It's up to you and your team to decide which ones to go with.

TDD with Test::Unit on Rails? View/Integration

I'm wondering how views, integration gets tested using the vanilla rails test stack.
I already know Cucumber/RSpec but want a simpler, faster, more productive testing solution and I think Test::Unit offers that.
For views: http://guides.rubyonrails.org/testing.html#testing-views
For integration: http://guides.rubyonrails.org/testing.html#integration-testing
The official guides are your best bet for the latest version of Test::Unit.
Also note the "Guides Index" link on the top of that page, which gives you all the links to the latest, official online guides.

RSpec documentation...where is it hiding?

Having a terrible time finding RSpec-2 (and rspec-rails) documentation. Specifically I want to look up all available Matchers... but how?
I've tried:
RSpec.info : outdated - RSpec 1.x
rdoc.info : seems useless, to me anyway. (incomplete?)
RSpec-Relish : confusing. incomplete? how would one look up available Matchers?
GitHub Wiki : scattered info. unorganized. incomplete?
Yes, I'm aware of The Book...but, seriously, isn't this stuff online?
Even tried rake doc:plugins but it didn't work. Too green to know why...
apparently there used to be some decent 1.x docs on rspec.rubyforge.org. but they're appear to be long gone...
Where are these docs hiding?
The first place to go is the official Relish docs, they have gotten a significant improvement over the years and are now my first place to look.
At the time of writing this answer originally, this gist was solid. It contains matchers for the following:
Capybara
Paperclip with Shoulda
Rspec Rails
Rspec Exceptions
Shoulda Matchers
Not sure why you feel rdoc.info isn't useful - here's the matcher docs there:
http://rubydoc.info/gems/rspec-expectations/2.0.1/RSpec/Matchers
It may be that you're looking in the wrong spot; these were in the RSpec::Expectations gem, which is split out from the core in Rspec 2.

Resources