开发者

In Ruby, how do you execute rspec code from a string rather than from a file?

开发者 https://www.devze.com 2023-01-04 13:13 出处:网络
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?

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
cl开发者_运维百科ass 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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消