Do routing specs support redirect routes? [RSpec]

Routing specs/tests specialize in testing whether a route maps to a specific controller and action (and maybe some parameters too). I dug into the internals of Rails and Journey a bit. RSpec and Rails (basically, some details left out) use Rails.application.routes.recognize_path to answer the question “is this routable?” For example: $ rails console > Rails.application.routes.recognize_path(“/business_users/1”, … Read more

Add I18n translations to rspec tests

In my code, a Rails 3 project, using RSpec 2, that is exactly the line I write: describe “GET ‘index'” do before do get ‘index’ end it “should be successful” do response.should be_redirect end it “should show appropriate flash” do flash[:warning].should == I18n.t(‘authorisation.not_authorized’) end end So I am not sure why you say it is … Read more

Setting roles through rolify in FactoryBot definition

I would rather use FactoryBot’s after(:create) callback to create roles (also see this issue for Rolify). Furthermore the method has_role? is used to check if a user has a specific role, to set a specific role you should use the add_role method. FactoryBot.define do factory :user do name ‘Test User’ email ‘[email protected]’ password ‘please’ password_confirmation … Read more

What are the advantages of Mocha over RSpec’s built in mocking framework? [closed]

Ruby mocking frameworks have evolved a lot since this question has been asked in 2009. So here is a little 2013 comparison: Expectations with Rspec-mocks: expect(user).to receive(:say_hello) with Mocha: user.expects(:say_hello).once Stubbing an object with Rspec-mocks: user = double(name: ‘John Doe’) with Mocha: user = stub(name: ‘John Doe’) Stubbing anything with Rspec-mocks: User.any_instance.stub(:name).and_return(‘John Doe’) with Mocha: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)