antonyw
2010-Jun-23 01:10 UTC
[rspec-users] RSpec, plugins and stubbing controller methods
Hello, I have some code that is going to be used in other applications, so I decided to bundle the code (mostly controllers and views) into a plugin to make sharing easier. I copied the RSpec tests for the controllers into the plugin as well. The plugin RSpec tests run, however when it gets to stubbing controller methods it does not work. For example: controller.stub!(:get_json_settings).and_return(Hash["host", "localhost", "port", "1234"]) results in an error ''undefined local variable or method controller''. I know this code was working fine before, since I could run the RSpec tests against the controller prior to it becoming a plugin. So, I wondered when it starts up what must RSpec be missing when running in the plugin? Doing a --trace on rake spec and rake spec:plugin show the same the things being invoked and executed. Just wondering if anyone might have come across this issue before, or have any suggestions? Thanks.... -- View this message in context: http://old.nabble.com/RSpec%2C-plugins-and-stubbing-controller-methods-tp28966280p28966280.html Sent from the rspec-users mailing list archive at Nabble.com.
David Chelimsky
2010-Jun-25 01:45 UTC
[rspec-users] RSpec, plugins and stubbing controller methods
On Jun 22, 2010, at 8:10 PM, antonyw wrote:> Hello, > > I have some code that is going to be used in other applications, so I > decided to bundle the code (mostly controllers and views) into a plugin to > make sharing easier. I copied the RSpec tests for the controllers into the > plugin as well. > > The plugin RSpec tests run, however when it gets to stubbing controller > methods it does not work. For example: > > controller.stub!(:get_json_settings).and_return(Hash["host", > "localhost", "port", "1234"]) > > results in an error ''undefined local variable or method controller''. > > I know this code was working fine before, since I could run the RSpec tests > against the controller prior to it becoming a plugin. So, I wondered when it > starts up what must RSpec be missing when running in the plugin? Doing a > --trace on rake spec and rake spec:plugin show the same the things being > invoked and executed. > > Just wondering if anyone might have come across this issue before, or have > any suggestions?What versions of RSpec and Rails?