Error Undefined method `sign_in_as! '

Asked

Viewed 126 times

0

I’m making the following mistake:

Failure/Error: sign_in_as!(user) Nomethoderror: Undefined method `sign_in_as! ' for

Estou com este error

Someone could help me! I’ve added the module, but nothing! I’m very grateful to everyone who can help me! https://github.com/3IBit/ticketee


inserir a descrição da imagem aqui

I tried to put :type => :Feature, but it didn’t work, I would know how to do it in helper (module). I’m a beginner still with BDD. I’m grateful for your help.

2 answers

0

What happens is that the helper is not loaded in your test.

You need to include them in the test

For example:

class AuthenticationTest < ActionView::TestCase
  include AuthenticationHelper
end
  • So, the problem I’m using in module, how would I call this module? or authenticationTest is already created automatically and I just need to include it in it?

  • Give the include in the module

  • Thank you very much, I got it solved! Actually I used a require 'support/authentication_helpers' The test passed! o/ But thanks again!

  • @Rodolfopexy, with the include AuthenticationHelper didn’t work out?

  • It didn’t work! " / only when called by require the file it worked.

0

Good morning, I did what you told me, but the error persists. I am using:

Archive: authentication_helpers.Rb

module AuthenticationHelpers
     def sign_in_as!(user)
         visit '/signin'
         fill_in "Name", with: user.name
         fill_in "Password", with: user.password
         click_button 'Sign in'
         expect(page).to have_content("Signed in successfully.")
     end
end

RSpec.configure do |c|
    c.include AuthenticationHelpers, type: :feature
end

Rspec.configure from |c| ... does not include in the whole test?

The file I am performing the test is as follows: editing_tickets_spec.Rb

require 'rails_helper'

require 'Capybara/Rails'

Feature "Editing tickets" from

let!(:project) { FactoryGirl.create(:project) }
let!(:user) { FactoryGirl.create(:user) }
let!(:ticket) do
  ticket =  FactoryGirl.create(:ticket, project: project) 
  ticket.update(user: user)
  ticket
end

before do
    sign_in_as!(user)
    visit "/"
    click_link project.name
    click_link ticket.title
    click_link "Edit Ticket"
end

scenario "Updating a ticket" do
    fill_in "Title", with: "Make it really shiny!"
    click_button "Update Ticket"

    expect(page).to have_content "Ticket has been updated."

    within("#ticket h2") do
        expect(page).to have_content("Make it really shiny!")
    end

    expect(page).to_not have_content ticket.title
end

scenario "Updating a ticket with invalid information" do
    fill_in "Title", with: ""
    click_button "Update Ticket"

    expect(page).to have_content("Ticket has not been updated.")
end

end

already dei include and tried to put also the type: :Feature Feature and before, but nothing! always appears this same error:

rodolfopeixoto@rodolfopeixoto-3IBit:~/portifolio/projeto/rails/ticketee$ rspec spec/features/editing_tickets_spec.rb 

FF

Failures:

1) Editing tickets Updating a ticket Failure/Error: sign_in_as!(user) Nomethoderror: Undefined method sign_in_as!' for #<RSpec::ExampleGroups::EditingTickets:0x007f199ed16e38> # ./spec/features/editing_tickets_spec.rb:17:inblock (2 levels) in '

2) Editing tickets Updating a ticket with invalid information Failure/Error: sign_in_as!(user) Nomethoderror: Undefined method sign_in_as!' for #<RSpec::ExampleGroups::EditingTickets:0x007f199ef569a0> # ./spec/features/editing_tickets_spec.rb:17:inblock (2 levels) in '

Finished in 0.04161 Seconds (files Took 1.52 Seconds to load) 2 examples, 2 failures

Failed examples:

rspec . /spec/Features/editing_tickets_spec.Rb:24 # Editing tickets Updating a ticket rspec . /spec/Features/editing_tickets_spec.Rb:37 # Editing tickets Updating a ticket with invalid information

I’m grateful my friend.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.