Class: Pretentious::RspecGenerator
- Inherits:
-
GeneratorBase
- Object
- GeneratorBase
- Pretentious::RspecGenerator
- Defined in:
- lib/pretentious/rspec_generator.rb
Instance Method Summary collapse
- #begin_spec(test_class) ⇒ Object
- #end_spec ⇒ Object
- #generate(test_instance, instance_count) ⇒ Object
- #indentation(level) ⇒ Object
-
#initialize(options = {}) ⇒ RspecGenerator
constructor
A new instance of RspecGenerator.
- #output ⇒ Object
- #whitespace(level = 0) ⇒ Object
Methods inherited from GeneratorBase
Constructor Details
#initialize(options = {}) ⇒ RspecGenerator
Returns a new instance of RspecGenerator.
3 4 5 6 7 8 9 10 11 |
# File 'lib/pretentious/rspec_generator.rb', line 3 def initialize( = {}) @deconstructor = Pretentious::Deconstructor.new indentation_count = [:indentation] || 2 @output_buffer = "" @_indentation = "" indentation_count.times do @_indentation << " " end end |
Instance Method Details
#begin_spec(test_class) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/pretentious/rspec_generator.rb', line 26 def begin_spec(test_class) buffer("#This file was automatically generated by the pretentious gem") buffer("require 'spec_helper'") whitespace buffer("RSpec.describe #{test_class.name} do") whitespace end |
#end_spec ⇒ Object
34 35 36 |
# File 'lib/pretentious/rspec_generator.rb', line 34 def end_spec buffer("end") end |
#generate(test_instance, instance_count) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/pretentious/rspec_generator.rb', line 42 def generate(test_instance, instance_count) if (test_instance.is_a? Class) #class methods class_method_calls = test_instance.method_calls_by_method generate_specs("#{test_instance.test_class.name}::", test_instance.test_class.name, class_method_calls, test_instance.let_variables) else buffer("context 'Scenario #{instance_count}' do",1) buffer("before do",2) buffer_inline(test_instance._deconstruct_to_ruby('@fixture', 3 * @_indentation.length)) buffer("end",2) whitespace method_calls = test_instance.method_calls_by_method generate_specs("#{test_instance.test_class.name}#","@fixture",method_calls, test_instance.let_variables) buffer('end',1) whitespace end end |
#indentation(level) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/pretentious/rspec_generator.rb', line 13 def indentation(level) buffer = "" level.times do buffer << @_indentation end buffer end |
#output ⇒ Object
38 39 40 |
# File 'lib/pretentious/rspec_generator.rb', line 38 def output @output_buffer end |
#whitespace(level = 0) ⇒ Object
22 23 24 |
# File 'lib/pretentious/rspec_generator.rb', line 22 def whitespace(level = 0) @output_buffer << "#{indentation(level)}\n" end |