is there a complete list of rspec api - ruby-on-rails

newbie. I would like a full list of the rspec api - particularly the built in matchers. It appears this web site: http://www.relishapp.com/rspec/rspec-expectations/v/3-4/docs/built-in-matchers appears to be done base on version.
the problem I have is, lets say I need a have(n).items matcher. I would have no idea this matcher existed by looking at version 3.4. I would potentially have to view all ~20 versions to discover it. Why is it done this way? Doesn't this seem like an awkward way to publish an API? is there a full list somewhere? :)

That matcher was removed in RSpec 3:
http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/
To find which matchers are available, check your Gemfile.lock to see which version of RSpec is in use, then refer to the corresponding documentation.

Related

RSpec "retest broken tests from last time" flag

Is there any way to retest previously broken tests?
So, say, I run rspec and several tests in different files and directories fail.
I fix something and now I have to manually specify all files and folders I want to retest or run tests for whole project again(It takes considerable amount of time for big projets).
What I was looking for is something like a flag
rspec --prev-failed-only
I realize that such flag would require considerable amount of additional actions from rspec, like storing results of previous tests and so on. But I think it would be super convenient to me.
Is there any such(or similar) tool/gem?
rspec-rerun gem does what you want : https://github.com/dblock/rspec-rerun
https://github.com/rspec/rspec-core/issues/456 has a good discussion on the topic of making rspec itself be able to rerun failed tests.
On the Giant Robots podcast, Sam Phippen of the core team mentioned this feature is due to be added to RSpec soon.
In case anyone else finds this, a month after the question was asked (open source <3 ) rspec 3.3 introduced the --only-failures option, also the delightfully handy --next-failure (-n) option. rspec --help for more info.

How to find all unused code in Ruby on Rails

I've inherited a Rails 2.3 app, which lacks a solid test suite. There is a fair amount of testing, but unfortunately, many of the tests test against old, unused models, controllers, and views.
Does anyone have a solid idea of how I might go about testing which models, controllers, views, helpers, etc. are completely unused, as well as look into the ones that ARE used and see which functions specifically are not used?
You can look at this answer, and perhaps some of the other answers listed: https://stackoverflow.com/a/9788511/485864
I would probably end up logging the methods that you have, and run your code through the paths and anything not listed in the log, may be examined to see if it is indeed not used.
RCov or SimpleCov won't do this what you want?
You can try to use RubyMine, a Rails IDE, to search for unused code. Try searching for method names and stuff like that. It's been a while since I used it so I dunno if it will have a highlight on unused methods.
Also, you can try some bash commands(grep/ack/find) to search for the code snippets.

it-block does not accept extra javascript argument anymore

I got a strange problem with minitest and capybara.
I am using rails 3.2.8 and test with minitest/capybara/poltergeist. Until now every went fine. I always could test my javascript stuff.
For a new project I downloaded rails 4 to get into it a little bit. And since minitest will be the testing framework I thought it would be easy. It was not. Truth be told, I am not a hero when it comes to setting up all the stuff. I just follow Ryan Bates. After a lot of adding and removing and updating a lot of gems I decided it wasn't worth to continue to use Rails 4. I had so many issues with getting into the groove with my integration tests. All the stuff I knew did not work as expected. The axe fell when almost everything worked until I wanted to test a javascript thing. I got this error:
.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/minitest-4.6.1/lib/minitest/spec.rb:190:in `it': wrong number of arguments (2 for 1) (ArgumentError)
because of this
describe "blabla" do
it "does not do what i want it to do", js: true do
pending
end
end
It will not accept the js: true argument. Funny thing is that the describe block will accept the js: true argument.
When I went back to Rails 3.2.8, because I thought it was a Rails 4 thing, this baby followed me right into a new testsuite. I tried hard to find an answer on Google but I can't find any. My other rails 3.2.8 projects still test fine, no complains about the javascript argument. But with the new apps: no javascript testing.
I am at a loss here. I have no idea where this is coming from. Since my other 3.2.8 apps still work fine, it has probably something to do with renewed gem versions? Has anybody seen this error message? I checked the complaining minitest/spec.rb file from the error message, line 190 for several minitest versions and nothing changed in the it-method.
Please let me know if you want to see stuff (Gemfile? test_helper.rb?) if you have any clue about what might be wrong. Thanks in advance!
Casper
Minitest's spec DSL does not accept a second parameter for the it blocks. The minitest-metadata gem adds support for the second argument, and the example shows how to configure Capybara to use it. Perhaps your existing projects use minitest-metadata and configure Capybara with it, and your new projects don't?

What happened to the "on Github" rails API documentation links?

A few months ago there was a feature in the Rails API documentation that let you visit the a Rails source file on Github by clicking "on Github". Ryan Bates even tweeted about it. This was a great feature because you could easily explore the source for the entire file instead of just for a single method.
Does anyone know what happened to this feature?
I believe they removed them when they started using Ajax for the show. This happened when they switched to sdoc. Perhaps its an sdoc limitation, as everyone seemed to enjoy it.
I would recommend posting on the google group and get a discussion going requesting more information and/or getting them back.
You can find the group here.
Rails documentation generated from using the standard Rdoc Rake task provided with the rails source still produces this extra link to github.
There's still a flag for it in the rakefile.
Whatever or whoever generates the documentation for the API must be omitting this flag.
It looks like the github links are back as of Rails 3.2.0!

Where are the downloadable Rails generators?

When I run...
$ script/generate
I get a list of installed generators and a message saying "More are available at http://wiki.rubyonrails.org/rails/pages/AvailableGenerators." However, the indicated wiki page says "This topic does not exist yet."
Does there exist some central repository of downloadable Rails generators?
In particular, I'd like one that creates the Rails scaffolding, but uses Haml instead of ERB.
It would also be neat if it would generate the Test::Unit tests but using the Shoulda enhancements.
That wiki was a wonderful resource back in the day, but it's long gone. I threw up a archive containing that page from when the wiki started wobbling. It's dated but you can at least see what was there.
As for now, look for gems (especially plugins) to provide the generators rather than expecting them as isolated resources. The gems command can be used to find whats available.
A lot of plugins come with their own generators. The one that springs to mind is restful_authentication because I have used it quite a bit.
Edit: Did you google here?
There's Rails Boost, which is a template generator. In fact, the template you want has already been generated -- that one uses HAML and Shoulda.

Resources