shoulda_runner 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +36 -0
- data/Rakefile +10 -0
- data/lib/shoulda_runner.rb +51 -0
- data/lib/shoulda_runner/ast_builder.rb +71 -0
- data/lib/shoulda_runner/version.rb +3 -0
- data/shoulda_runner.gemspec +34 -0
- metadata +127 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 85cb97c8c9697b94f7963507b22fb4123ac9fda3
         | 
| 4 | 
            +
              data.tar.gz: 9b6c9b84b4617ad84dee53104853df87fd0e0e9a
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: e50ca46a01cb3f9659a61e90225ce8e6e20aef61c604be9db13d8b556507451b6b88efe2d9d0d55177f505a2d3b5fbc38865977ae27fda26bac2b98a1f9a12cb
         | 
| 7 | 
            +
              data.tar.gz: 3e7df1ade8cb67de0b6d611cfd050310b59289d02bac55fc2290dca474656cf2b09e2232f2893ded4759426653cab7c2e4cb752bbc4c83864e6bcd3049bac58a
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.ruby-gemset
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            shoulda-vim
         | 
    
        data/.ruby-version
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            2.2.1
         | 
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,36 @@ | |
| 1 | 
            +
            # ShouldaVim
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/shoulda_vim`. To experiment with that code, run `bin/console` for an interactive prompt.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            TODO: Delete this and the text above, and describe your gem
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            ## Installation
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            Add this line to your application's Gemfile:
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ```ruby
         | 
| 12 | 
            +
            gem 'shoulda_vim'
         | 
| 13 | 
            +
            ```
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            And then execute:
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                $ bundle
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            Or install it yourself as:
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                $ gem install shoulda_vim
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            ## Usage
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            TODO: Write usage instructions here
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            ## Development
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            ## Contributing
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/shoulda_vim.
         | 
| 36 | 
            +
             | 
    
        data/Rakefile
    ADDED
    
    
| @@ -0,0 +1,51 @@ | |
| 1 | 
            +
            require 'shoulda_runner/version'
         | 
| 2 | 
            +
            require 'shoulda_runner/ast_builder'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module ShouldaRunner
         | 
| 5 | 
            +
              class Parser
         | 
| 6 | 
            +
                def initialize(test_file_path)
         | 
| 7 | 
            +
                  @path = test_file_path
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def select_test(linenumber)
         | 
| 11 | 
            +
                  test_names[linenumber]
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                private
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                def test_names
         | 
| 17 | 
            +
                  @ast ||= build_ast
         | 
| 18 | 
            +
                  hash = {}
         | 
| 19 | 
            +
                  @ast.each do |node|
         | 
| 20 | 
            +
                    if node.children.empty?
         | 
| 21 | 
            +
                      from = node.content[:line_range][:from]
         | 
| 22 | 
            +
                      to   = node.content[:line_range][:to]
         | 
| 23 | 
            +
                      test_name = build_test_name(node)
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                      from.upto(to) do |line|
         | 
| 26 | 
            +
                        hash[line] = test_name
         | 
| 27 | 
            +
                      end
         | 
| 28 | 
            +
                    end
         | 
| 29 | 
            +
                  end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  hash
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                def build_test_name(node)
         | 
| 35 | 
            +
                  test_name_string = node.content[:name]
         | 
| 36 | 
            +
                  parent = node.parent
         | 
| 37 | 
            +
                  while parent != nil
         | 
| 38 | 
            +
                    test_name_string = "#{parent.content[:name]}#{test_name_string}"
         | 
| 39 | 
            +
                    parent = parent.parent
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  test_name_string
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                def build_ast
         | 
| 46 | 
            +
                  ast_builder = AstBuilder.new(@path)
         | 
| 47 | 
            +
                  ast_builder.parse
         | 
| 48 | 
            +
                  @ast = ast_builder.ast
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
            end
         | 
| @@ -0,0 +1,71 @@ | |
| 1 | 
            +
            require 'tree'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module ShouldaRunner
         | 
| 4 | 
            +
              class AstBuilder
         | 
| 5 | 
            +
                attr_reader :ast
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def initialize(path)
         | 
| 8 | 
            +
                  @source = File.read(path)
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def parse
         | 
| 12 | 
            +
                  stack = []
         | 
| 13 | 
            +
                  each_source_code_line do |line, number|
         | 
| 14 | 
            +
                    if line =~ /^class\s/
         | 
| 15 | 
            +
                      stack = []
         | 
| 16 | 
            +
                      node = class_node(line)
         | 
| 17 | 
            +
                      stack.push node
         | 
| 18 | 
            +
                    elsif line =~ /^context\s/
         | 
| 19 | 
            +
                      stack.push context_node(line)
         | 
| 20 | 
            +
                    elsif line =~ /^should\s/
         | 
| 21 | 
            +
                      stack.push should_node(line, number)
         | 
| 22 | 
            +
                    elsif line =~ /(do|do\s\|.+\|$)/
         | 
| 23 | 
            +
                      stack.push disposable_node(line)
         | 
| 24 | 
            +
                    elsif line =~ /^end$/
         | 
| 25 | 
            +
                      node = stack.pop
         | 
| 26 | 
            +
                      node.content[:line_range][:to] = number if node.content[:line_range]
         | 
| 27 | 
            +
                      parent = stack.pop
         | 
| 28 | 
            +
                      if parent
         | 
| 29 | 
            +
                        parent << node unless node.content[:dispose]
         | 
| 30 | 
            +
                        stack.push parent
         | 
| 31 | 
            +
                      else
         | 
| 32 | 
            +
                        @ast = node
         | 
| 33 | 
            +
                      end
         | 
| 34 | 
            +
                    end
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                private
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                def class_node(line)
         | 
| 41 | 
            +
                  matches = line.match(/^class\s(?<class_name>\w+)\s<\s.+$/)
         | 
| 42 | 
            +
                  class_name = "#{matches[:class_name]}#test_: "
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  Tree::TreeNode.new(class_name, { name: class_name, source_line: line })
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                def context_node(line)
         | 
| 48 | 
            +
                  matches = line.match(/^context\s('|")(?<context_text>[\w\s]+)('|")\sdo$/)
         | 
| 49 | 
            +
                  context_text = "#{matches[:context_text]} "
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  Tree::TreeNode.new(context_text, { name: context_text, source_line: line })
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                def should_node(line, line_number)
         | 
| 55 | 
            +
                  matches = line.match(/^should\s('|")(?<should_text>[\w\s]+)('|")\sdo$/)
         | 
| 56 | 
            +
                  should_text = "should #{matches[:should_text]}. "
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                  Tree::TreeNode.new(should_text, { name: should_text, source_line: line, line_range: { from: line_number } })
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                def disposable_node(line)
         | 
| 62 | 
            +
                  Tree::TreeNode.new(line, { name: line, dispose: true })
         | 
| 63 | 
            +
                end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                def each_source_code_line
         | 
| 66 | 
            +
                  @source.each_line.map(&:chomp).map(&:lstrip).each.with_index do |line, index|
         | 
| 67 | 
            +
                    yield line, index + 1
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
              end
         | 
| 71 | 
            +
            end
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 2 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 3 | 
            +
            require 'shoulda_runner/version'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |spec|
         | 
| 6 | 
            +
              spec.name          = "shoulda_runner"
         | 
| 7 | 
            +
              spec.version       = ShouldaRunner::VERSION
         | 
| 8 | 
            +
              spec.authors       = ["Giuseppe Modarelli"]
         | 
| 9 | 
            +
              spec.email         = ["giuseppe.modarelli@gmail.com"]
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              spec.summary       = %q{Generate the test name necessary to run a single test case}
         | 
| 12 | 
            +
              spec.description   = %q{If your using the shoulda gem this gem will generate the test name to run a single test}
         | 
| 13 | 
            +
              spec.homepage      = ""
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
         | 
| 16 | 
            +
              # delete this section to allow pushing this gem to any host.
         | 
| 17 | 
            +
              if spec.respond_to?(:metadata)
         | 
| 18 | 
            +
                spec.metadata['allowed_push_host'] = "https://rubygems.org"
         | 
| 19 | 
            +
              else
         | 
| 20 | 
            +
                raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              spec.files         = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         | 
| 24 | 
            +
              spec.bindir        = "exe"
         | 
| 25 | 
            +
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 26 | 
            +
              spec.require_paths = ["lib"]
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              spec.add_dependency "rubytree"
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              spec.add_development_dependency "bundler", "~> 1.10"
         | 
| 31 | 
            +
              spec.add_development_dependency "rake", "~> 10.4.2"
         | 
| 32 | 
            +
              spec.add_development_dependency "minitest"
         | 
| 33 | 
            +
              spec.add_development_dependency "byebug"
         | 
| 34 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,127 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: shoulda_runner
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.2.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Giuseppe Modarelli
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: exe
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2017-08-03 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: rubytree
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - ">="
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '0'
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - ">="
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '0'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: bundler
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '1.10'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '1.10'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: rake
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - "~>"
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: 10.4.2
         | 
| 48 | 
            +
              type: :development
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - "~>"
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: 10.4.2
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: minitest
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ">="
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 62 | 
            +
              type: :development
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - ">="
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: byebug
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - ">="
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: '0'
         | 
| 76 | 
            +
              type: :development
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - ">="
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: '0'
         | 
| 83 | 
            +
            description: If your using the shoulda gem this gem will generate the test name to
         | 
| 84 | 
            +
              run a single test
         | 
| 85 | 
            +
            email:
         | 
| 86 | 
            +
            - giuseppe.modarelli@gmail.com
         | 
| 87 | 
            +
            executables: []
         | 
| 88 | 
            +
            extensions: []
         | 
| 89 | 
            +
            extra_rdoc_files: []
         | 
| 90 | 
            +
            files:
         | 
| 91 | 
            +
            - ".gitignore"
         | 
| 92 | 
            +
            - ".ruby-gemset"
         | 
| 93 | 
            +
            - ".ruby-version"
         | 
| 94 | 
            +
            - ".travis.yml"
         | 
| 95 | 
            +
            - Gemfile
         | 
| 96 | 
            +
            - Gemfile.lock
         | 
| 97 | 
            +
            - README.md
         | 
| 98 | 
            +
            - Rakefile
         | 
| 99 | 
            +
            - lib/shoulda_runner.rb
         | 
| 100 | 
            +
            - lib/shoulda_runner/ast_builder.rb
         | 
| 101 | 
            +
            - lib/shoulda_runner/version.rb
         | 
| 102 | 
            +
            - shoulda_runner.gemspec
         | 
| 103 | 
            +
            homepage: ''
         | 
| 104 | 
            +
            licenses: []
         | 
| 105 | 
            +
            metadata:
         | 
| 106 | 
            +
              allowed_push_host: https://rubygems.org
         | 
| 107 | 
            +
            post_install_message: 
         | 
| 108 | 
            +
            rdoc_options: []
         | 
| 109 | 
            +
            require_paths:
         | 
| 110 | 
            +
            - lib
         | 
| 111 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 112 | 
            +
              requirements:
         | 
| 113 | 
            +
              - - ">="
         | 
| 114 | 
            +
                - !ruby/object:Gem::Version
         | 
| 115 | 
            +
                  version: '0'
         | 
| 116 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 117 | 
            +
              requirements:
         | 
| 118 | 
            +
              - - ">="
         | 
| 119 | 
            +
                - !ruby/object:Gem::Version
         | 
| 120 | 
            +
                  version: '0'
         | 
| 121 | 
            +
            requirements: []
         | 
| 122 | 
            +
            rubyforge_project: 
         | 
| 123 | 
            +
            rubygems_version: 2.4.5
         | 
| 124 | 
            +
            signing_key: 
         | 
| 125 | 
            +
            specification_version: 4
         | 
| 126 | 
            +
            summary: Generate the test name necessary to run a single test case
         | 
| 127 | 
            +
            test_files: []
         |