In minitest_helper.rb I have seen the minitest class defined as:
MiniTest::Rails::Spec
or
MiniTest::Spec
What is the difference between these definitions? I have also noticed where the basic class is set...such as
MiniTest::Spec::TYPES.last[1] = MiniTest::Rails::Spec
What does this accomplish?
MiniTest::Rails::Spec is for testing rails sites, using the rspec-like dsl in minitest. MiniTest::Spec is just the plain rspec like minitest without the additional rails functionality.
The last line is adding rails matchers to standard MiniTest::Spec. There's a comment in the source explaining it: https://github.com/seattlerb/minitest/blob/master/lib/minitest/spec.rb#L97
Related
I'm upgrading an old Rails 2 app to 3.2. Rspec is giving me this error:
expected /app/models/api/key.rb to define Api::Key
The actual file is:
module API
class Key
So the capitalization is wrong according to Rails convention. I'd like to avoid project wide searching and trying to change everywhere the constant is referenced. Is there any way to tell Rails the module is in all capitals?
For reference, I did try to use the inflector:
ActiveSupport::Inflector.inflections do |inflect|
inflect.acronym "API"
end
Is it a caps issue? You have "API" and the error says its expecting "Api". I'm not sure if that would matter or not but it seems like it would
I have a gem, that declares the class FulltextRow
I created an initializer called hacks.rb were I open classes from different gems.
I added the following code:
FulltextRow.class_eval do
....
end
However, If I don't require the class I get the exception:
uninitialized constant FulltextRow (NameError)
But it works well If I do:
require 'fulltext_row'
FulltextRow.class_eval do
....
end
My question is:
Why do I need to require a class that is defined in a gem? Aren't they automatically required?
I would love to help you out but it's hard to troubleshoot this with the lack of information given. I do have two suggestions, though.
1) You should verify the gem is loading properly within the gem. What I mean is to have supporting tests that affirm that the gem is working as intended. I've had instances where my gem's classes were not loading because I wasn't setting up the file structure right or had a silly typo somewhere.
2) It is also possible that your gemfile has set to not load the gem automatically.
gem full_text_row, require: false
Good luck!
A simple question. Does this version support generators?
I wanted to test out using it and follow along with Ryan Bates screen cast which I uses a different version.
I've been playing with tables today and want to see how this works using the generator with a scaffold generated model and all its components.
Running rails g bootstrap:themed returns
Could not find generator bootstrap:themed
So I tried to reinstall with rails g install:bootstrap
Error similar which lead me to try to find if it supports these commands.
Thanks
It doesn't need generators for asset files, since we hook into the asset pipeline through the use of a Rails Engine - configuration options are available through the use of variables (use this as a reference, Sass variables are actually $x rather than #x and need to be defined before importing bootstrap), Sass' #extend, and Bootstrap's #makeRow and #makeColumn mixins, along with the other Bootstrap mixins.
Themed scaffold would be interesting but generally would be a pain to maintain - view scaffolding tends to get ripped apart pretty quickly anyway. Perhaps a 'sane' application.html.erb layout generator could be useful.
So yeah, we currently have no generators, don't need an asset one, themed scaffold probably not coming soon unless someone is interested enough to do the work on it, potentially a layout generator in the pipeline.
Checkout
https://github.com/decioferreira/bootstrap-generators
Seems to be what you are asking for.
-Rick
I am a beginner in learning Ruby and Rails.
I was going through the following section on Rails 3.2.1 Guide:
http://guides.rubyonrails.org/routing.html#paths-and-urls
which says:
Creating a resourceful route will also expose a number of helpers to the controllers
in your application. In the case of resources :photos:
photos_path returns /photos
new_photo_path returns /photos/new
edit_photo_path(:id) returns /photos/:id/edit (for instance, edit_photo_path(10) returns /photos/10/edit)
photo_path(:id) returns /photos/:id (for instance, photo_path(10) returns /photos/10)
I am curious to know how and when in the lifecycle of a request are these helpers, i.e. new_photo_path, edit_photo_path etc created and where in the source code I can found the code doing the same.
I was navigating through the code in the following file /gems/actionpack-3.2.1/lib/action_dispatch/routing/mapper.rb and I guess the code in this file is creating the above helpers.Please correct me if I am wrong.
Thanks,
Jignesh
Essentially, yes, that is correct. For more information, you should check out the Routing Walkthrough series that Ryan Bates did last September, where he walks through some of the Rails code that controls routing.
If you use the generators (e.g. rails g controller NewController) the helpers are automatically created and places in ./app/helpers with similar nomenclature. If you are doing the controllers by hand then you would need to create your own, e.g. new_helper. By default though all controllers load application_helper.rb.
If you are not going to use a helper method in more than one controller/view it is best to put it in its own helper file. This guide may help explain it more.
Update
The helper methods are written by you based on your needs. The code for the helper generator can be found here
After all the hussle about Rails 3, can I, after all, painlessly use DataMapper without almost changing my ActiveRecord code so that I could run my Rails at GAE without any bother?
Well, you still have to add the properties for DataMapper, and a bunch of code in the gems you are using might not be ORM-agnostic. And you have to change your queries to the DM syntax (which is IMO more beautiful than the AR one), or you can use some of the old AR ones by using the gem dm-ar-finders. And what's GAE?