Hi all, my first question here.
Let say I have the following code in application_helper.rb
def do_something
if action_name == 'index'
'do'
else
'dont'
end
end
which will do something if called within index action
Q: How do I rewrite the helper spec for this in application_helper_spec.rb to meet simulate a call from 'index'...
I'm writing a ruby program that executes some external command-line utilities. How could I mock the filesystem from my rspec tests so that I could easily setup some file hierarchy and verify it after testing. It would also be best to be implemented in ram so that tests would run quickly.
I realize that I may not find a portable solutio...
I am trying to write an rspec test for a controller that accesses a
model Group.
@request.env['HTTP_REFERER'] = group_url(@mock_group) ### Line 49
I get this:
NoMethodError in 'ActsController responding to create should redirect to :back'
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.rewr...
When using topfunky's RStakeout, the color in the result of the spec command is lost. This happens even when adding the --color flag.
...
class A
def initialize
@x = do_something
end
def do_something
42
end
end
How can I stub do_something in rspec, before the original implementation is called (thus assigning 42 to @x)? And without changing the implementation, of course.
...
I'm trying to verify that a parameter is an instance of a specific class in Rails:
def schedule(action, *args)
if arg.is_a? Aircraft
...
end
end
I'm doing this in a library class (the file is in lib/) and I get an uninitialized constant Aircraft error. Aircraft is a model class, with a corresponding aircraft.rb file in app/mod...
I want to use RSpec mocks to provide canned input to a block.
Ruby:
class Parser
attr_accessor :extracted
def parse(fname)
File.open(fname).each do |line|
extracted = line if line =~ /^RCS file: (.*),v$/
end
end
end
RSpec:
describe Parser
before do
@parser = Parser.new
@lines = mock("lines")
@lines...
I'm trying to write a Cucumber scenario that requires me to have a logged in user - that would normally be quite simple but I'm only using OpenID authentication (curtosy of the authentication plugin). However after digging through the open_id_authentication plugins guts I'm not sure how I could achieve this within Cucumber.
...
I have a number of view specs that need certain methods to be stubbed. Here's what I thought would work (in spec_helper.rb):
Spec::Runner.configure do |config|
config.before(:each, :type => :views) do
template.stub!(:request_forgery_protection_token)
template.stub!(:form_authenticity_token)
end
end
But when I run any v...
When should I use specs for Rails application and when Cucumber (former rspec-stories)? I know how both work and actively use specs, of course. But it still feels weird to use Cucumber. My current view on this, is that it's convenient to use Cucumber when you're implementing application for the client and do not understand how the whole ...
Can someone recommend a good, up-to-date tutorial for a complete beginner on one of the major testing frameworks for Ruby, such as Rspec or Shoulda? I'd like to find something that doesn't assume any knowledge about the framework or about testing in general. For example, if the tutorial explained the distinction between TDD and BDD, that...
I'm sorry, but this is beginning to feel like kicking myself in the head. I'm completely baffled by RSpec. Have watched video after video, read tutorial after tutorial, and still I'm just stuck on square one.
=== here is what I'm working with
http://github.com/fudgestudios/bort/tree/master
=== Errors
F
1)
NoMethodError in 'biddin...
Mac OS 10.4
rspec (1.1.11, 1.1.4, 1.1.3, 0.5.15)
rspec-rails (1.1.11)
rspec_generator (0.5.15)
rails 2.2.2
ruby 1.8.6 (2007-03-13 patchlevel 0) [universal-darwin8.0]
Created a new project...
$ rails myproject
Installed rspec into the project...
$ script/generate rspec
Generated a resource...
$ script/generate rspec_scaffold myre...
What is the best way to ensure that the proper RJS is being generated in a Controller action?
For example, I want to ensure that a div is highlighted as such:
def new
render :update do |page|
page.visual_effect :highlight, :some_div
end
end
Rant:
This is quickly becoming one of the reasons I grow tired of RSpec after using it...
After doing some work with Ruby, Rails, and RSpec last summer and I learned to TATFT. Now I can't write code without writing tests first.
I'm taking a programming course in C next year, and I would like to learn to write C test-driven. Is it a good idea (or even possible) to do TDD with C? If so, are there any good testing frameworks co...
Where does Rails store data created by saving activerecord objects during tests?
I thought I knew the answer to that question: obviously in the _test database. But it looks like this is not true!
I used this system to test what's happening to saved ActiveRecord data during rspec tests:
$ rails -d mysql test
$ cd test
$ nano config/d...
I'm building a Rails application that requires some models to interact with some necessary Java libraries. To do this, I want to use Rails on on MRI - not JRuby or RBJ. The Java code only needs read access to the database tables managed by the Rails app.
One way to do this is to set up a Servlet that reads the Rails app's database table...
I've got some code in the lib/ directory that don't really belong under controls, models or helpers. I'd like to write some rspec tests for this code, but am not sure where they should go under the spec/ directory. Is there a convention that's commonly followed?
...
If a customer has a requirement - product names should not be more than 50 characters long, does this suggest a story/spec should be written for this if the framework being used already has a well tested validation framework (Rails for instance).
To be more general, should one test the specifics for each area of validation for the parti...
I want to start BDD on Ruby On Rails what should I learn?
I don't know anything about BDD, RSpec or Cucumber. What is the best way to learn? Tutorials? Something that cover things like 'What behavior I should test?' etc.
thanks!
...