Hi Struts how many execute method is possible in Action class.
Related
I have a class with a Klass::save method. This method will create a new instance of Klass, and then call either inst.create or inst.update depending.
I want to write an rspec test like this:
expect(instance_created_within_class_method).to receive(:create)
Can I access an object that is created during the running of the method I'm testing?
expect_any_instance_of(Class).to receive(:create) may be what you're looking for.
To call through the method you can add .and_call_original to the end of it.
Check out the RSpec documentation surrounding mocks and expectations: https://relishapp.com/rspec/rspec-mocks/v/2-14/docs/message-expectations/expect-a-message-on-any-instance-of-a-class!
I have this helper for a session in rails 5 and it's calling to the user table and then session table, that's because I have it related in my database, the code is the following one:
module SessionsHelper
def generate_user_session
session_build = user.sessions.build
session_build.generate_access_token
session_build.save!
end
end
The problem is when I called the method in a controller it appears this error:
undefined local variable or method 'user'
I know this error is due to I'm not referring well to my helper in my controller, the question is...
How is the correct form I can call a method from a helper in my controller?
Note: Consider that in my helper I'm calling to my table user that is also calling the table sessions.
You are trying to access a variable (user) that's only available on your controller. You may try to set and use #user as instance_variable.
But as tadman write, you shouldn't use helper to controller propose.
If it is for session proposes you could use a concern or create a new Class to deal with this.
Seems simple but I can't find the answer anywhere?
I just want to test whether an object is an instance of a certain class.
There's the IsKindOfClass method, but what argument can I pass it?
I wanted to write it like in Objective-C :
if (view.IsKindOfClass(AdvicePageView.Class)) {
but the Class method / attribute doesn't exist.
How can I pass my class to IsKindOfClass?
this is basic C#
if (MyView is MyTypeOfView) then
where MyView is an instance and MyTypeOfView is a class
I am writing a small tool for validating method arguments in Ruby. Ideally, the functionality would be like this:
class Test
extend ArgValidator
def say(word)
puts word
end
validate_args(:say) do
raise(ArgumentError) if not word.is_a?(String)
end
end
Test.new.say(3) # => ArgumentError
That is, the ArgValidator module provides a validate_args method that takes an instance method name and a block. Calling validate_args(<meth>) causes the validation code (supplied in the block) to be run before the method body. The validation block is executed against the bindings of the method body. There are two features of the above code that I am specifically striving for:
the target method body has no knowledge of the validation code (it is decorated)
the validation block should have access to the same bindings as the method body, without needing to hardcode a duplicated method signature
My current approach is to have validate_args decorate the target method with the validation code. By using Method#parameters, I can get signature information from the target method and come very close to dynamically replicating the bindings of the method body itself. Unfortunately, #parameters provides no information about default argument values.
Is there any way to achieve my goal?
As I am new to OO programming this may seem a trite question.
I am trying to write a basic End-User testing framework which has a class Pageobject with the majority of method code.
I have a testing script which instantiates the selenium driver at the top-level and then I have a number of Page object method calls to "do stuff".
If I instantiate the driver at the top-level then I need to pass the driver object to any method that needs it which is fine but I would like to minimise the number of parameters passed to a method call for the saake of readability.
eg. home_page.login(this_user) reads a little better than home_page.login(this_user, selenium_driver).
I know global variables are frowned upon so is there any other way that all method can have access to an object in a different scope.
I access all my Page objects in my tests through a PageRepo class that initializes all of my Page objects.
I initialize the PageRepo class in a base class that my test classes inherit from This is also where I initialize my WebDriver.
so my tests look like this.
PageRepo.HomePage().DoSomething()