Reputation: 2118
I've been searching around for a while, and did not find a clear explanation about testing structure in RoR. (I'm learning with Michael Hartl's book).
The 2nd question comes from this error:
undefined method `visit' for #<RSpec::Core::ExampleGroup: ...
which occurs as soon as my very simple test file is not in /spec/requests (but in /spec/views):
require 'spec_helper'
describe "Home page" do
subject { page }
###1
describe "title" do
before { visit root_path }
it { should have_selector('h1', text: 'Welcome') }
it { should have_selector('title', text: 'Home') }
end
end
Upvotes: 0
Views: 64
Reputation: 14750
1) No, you don't need the test
folder. Only spec
, unless you're using Test::Unit.
2) You can order spec
however you want. The general suggested format is
spec/
controllers/
views/
models/
lib/ #Only if you have stuff in lib you need to test
spec_helper.rb
with names like spec/controllers/items_controller_spec.rb
, and spec/models/item_spec.rb
3) I'm not sure what you mean. For RSpec, you just need to make a file that uses its syntax to test certain pieces of your Ruby code. It doesn't create a script -- you do.
For your last question about visit
:
It seems like you're trying to use a Capybara method (visit
). Capybara takes care of visiting your site in a browser, not RSpec.
Upvotes: 2
Reputation: 40277
There is one specific folder structure you need to use in order to run Capybara acceptance tests. These are tests that have "visit" in them
Capybara 1.0
spec/requests
Capybara 2.0
spec/features
Upvotes: 1
Reputation: 45164
test
folder is generally used for Test::Unit stuff. You can delete or keep it; doesn't hurt to leave it.app/models/user.rb
, for example, your spec should be in spec/models/user_spec.rb
.Upvotes: 1