-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds the ability to spec test an arbitrary string #619
base: master
Are you sure you want to change the base?
Adds the ability to spec test an arbitrary string #619
Conversation
We are building a web service that will enable rspec-puppet testing of POSTed Puppet code. The use case is a tutorial that will allow users to type in a snippet of Puppet code and get immediate validation of whether they'd completed the exercise correctly. Example test: ```Ruby require 'rspec-puppet' RSpec::configure do |c| c.string = "package { 'httpd': ensure => present, }" end describe 'apache', :type => :string do let(:node) { 'testhost.example.com' } describe 'when called with no parameters on redhat' do let (:facts) { { ... } } it { should contain_package('httpd').with({ 'ensure' => 'present', }) } end end ```
Rather than making the input string an RSpec setting, would you mind changing it to be a helper on the example instead? e.g. |
Hmm. I'm not opposed to that idea, but how would we be able to invoke a spec programmatically then? We're using this now like so: def run_rspec(spec_path, str)
require 'rspec/core'
# rspec needs an IO object to write to. We just want it as a string...
data = StringIO.new
RSpec::configure do |c|
c.output_stream = data
c.formatter = 'json'
end
# require *after* setting the output stream or it screams at us
# String input depends on https://github.com/rodjek/rspec-puppet/pull/619
require 'rspec-puppet'
RSpec::configure do |c|
c.string = str
end
begin
RSpec::Core::Runner.run([spec_path])
return data.string
rescue StandardError, LoadError => e
return "Error running spec test: #{e.message}",
end |
@binford2k @scotje is this still relevant? If yes, please link to a internal ticket to capture that. |
@binford2k Do you intend to return to this? If not, would you be OK closing the PR? |
@sanfrancrisko I would like to get it merged, but I don't know how to accomplish what @rodjek asked for and retain the ability to run a spec test from an arbitrary file against an arbitrary string. |
We are building a web service that will enable rspec-puppet testing of
POSTed Puppet code. The use case is a tutorial that will allow users to
type in a snippet of Puppet code and get immediate validation of whether
they'd completed the exercise correctly.
Example test: