currently I'm stuck on an error that has been plaguing me for quite some time. Any help would be greatly appreciated.
Explanation : I've tried to run 'bundle exec rspec spec/' command in my console to test whether all the scripts are working however I'm greeted with the error "undefined method 'subject' for main:object (NoMethodError)
Code for spec/requests/static_pages.rb file
require 'spec_helper
describe "Static pages" do
describe "Home page" do
before {visit root_path}
it "should have the content 'Sample App'" do
expect(page).to have_content('Sample App')
end
it "should have the title 'Home'" do
expect(page).to have_title("Home")
end
end
describe "Help page" do
before {visit help_path}
it "should have the content 'Help'" do
expect(page).to have_content('Help')
end
it "should have the title 'Help'" do
expect(page).to have_title("Help")
end
end
describe "About page" do
before {visit about_path}
it "should have the content 'About Us'" do
expect(page).to have_content('About Us')
end
it "should have the title 'About Us'" do
expect(page).to have_title("About Us")
end
end
describe "Contact Page" do
before {visit contact_path}
it "should have the content 'Contact'" do
expect(page).to have_content('Contact')
end
it "should have the title 'Contact'" do
expect(page).to have_title("Contact")
end
end
end
and for spec/models/user_spec.rb
require 'spec_helper'
describe User do
before do
@user = User.new(name: "Example User", email: "[email protected]", password: "foobar", password_confimation: "foobar")
end
subject { @user }
it { should respond_to(:name) }
it { should respond_to(:email) }
it { should respond_to(:password_digest)}
it { should respond_tp(:password)}
it { should respond_to(:password_confimation)}
it { should respond_to(:authenticate)}
it { should be_valid }
describe "with a password that's too short" do
before { @user.password = @user.password_confirmation = "a" * 5 }
it { should be_invalid }
end
describe "return value of authenticate method" do
before { @user.save }
let(:found_user) { User.find_by(email: @user.email) }
describe "with valid password" do
it { should eq found_user.authenticate(@user.password) }
end
describe "with invalid password" do
let(:user_for_invalid_password) { found_user.authenticate("invalid") }
it { should_not eq user_for_invalid_password }
specify { expect(user_for_invalid_password).to be_false }
end
end
code for specified file 'generic.rb'
'subject {page}
describe "Home page" do
before {visit root_path}
it {should have_content ('Sample App')}
it {should have_title(full_title(''))}
it {should_not have_title('| Home')}
end'