Reputation: 1658
I'm new to Ruby and RSpec. I want to create very simple RSpec test:
# test_spec.rb
require 'spec_helper'
describe TestController do
puts(Time.now)
end
But when I run the code this way rspec test_spec.rb
I get error:
`<top (required)>': uninitialized constant TestController (NameError)
Can you give me some idea where I'm wrong?
Upvotes: 0
Views: 60
Reputation: 51
This error is because after the describe you need a string with the description and you are leaving it without quotes.
describe '3pController' do
puts(Time.now)
end
But the tests should be structured as follows
inside this link I will leave the documentation Basic structure
Here you can see a basic example of a test
describe 'sum 2 + 2 equal 4' do
it { expect(2 + 2).to eq(4)}
end
Upvotes: 2
Reputation: 114138
If you pass a class to describe
, RSpec attempts to create an instance of that class. If the specified class does not exist, you get an error.
You can pass a string instead:
describe "my first test" do
it "does something" do
expect(1).to be_odd
end
end
Running the above:
$ rspec -fd test_spec.rb
my first test
does something
Finished in 0.00178 seconds (files took 0.10381 seconds to load)
1 example, 0 failures
Upvotes: 3