tags:

views:

50

answers:

1

I am trying to execute rspec code passed in to a Ruby process as a string. How can I execute rspec from within a Ruby process rather than from the commandline and capture the results?

# Ruby code    
code = '
#solution
class User
  def in_role?(role)
    true
  end  
end

#Tests to pass
describe User do
  it "should be in any roles assigned to it" do
    user = User.new
    user.should be_in_role("assigned role")
  end
end
'
# spec code
# numExamples = examples
# numFailures = failures
+1  A: 

Is there any reason you should get the code as a string in first place? If you want to have access to the data rspec produces, you can try using a custom RSpec formatter

Chubas
I won't have access to a file system or commandline. I need to run spec from within Ruby code.
Chris