Module: SpecWatchr::Specs

Included in:
SpecWatchr
Defined in:
lib/rspec-rails-watchr-emacs.rb

Instance Method Summary collapse

Instance Method Details

#check_if_bundle_neededObject



172
173
174
175
176
177
178
# File 'lib/rspec-rails-watchr-emacs.rb', line 172

def check_if_bundle_needed
  if `bundle exec #{rspec_command} -v` == `#{rspec_command} -v` 
    @bundle = ""
  else
    @bundle = "bundle exec "
  end
end

#default_rails_matcher(path, specs) ⇒ Object



203
204
205
# File 'lib/rspec-rails-watchr-emacs.rb', line 203

def default_rails_matcher path, specs
  specs.grep(/\b#{path}((_spec)?\.rb)?$/)
end

#match_specs(path, specs) ⇒ Object



207
208
209
210
211
# File 'lib/rspec-rails-watchr-emacs.rb', line 207

def match_specs path, specs
  matched_specs = @custom_matcher.call(path, specs) if @custom_matcher
  matched_specs = default_rails_matcher(path, specs) if matched_specs.nil?
  matched_specs
end

#rspec(options) ⇒ Object



180
181
182
183
184
185
186
# File 'lib/rspec-rails-watchr-emacs.rb', line 180

def rspec options
  unless options.empty?
    results = run("#{@bundle}#{rspec_command} #{options}")
    # notify( success ? '♥♥ SUCCESS :) ♥♥' : '♠♠ FAILED >:( ♠♠' )
    rspec_send_results(results)
  end
end

#rspec_allObject



188
189
190
# File 'lib/rspec-rails-watchr-emacs.rb', line 188

def rspec_all
  rspec 'spec'
end

#rspec_commandObject



155
156
157
# File 'lib/rspec-rails-watchr-emacs.rb', line 155

def rspec_command
  @rspec_command ||= File.exist?('./.rspec') ? 'rspec' : 'spec'
end

#rspec_files(*files) ⇒ Object



192
193
194
# File 'lib/rspec-rails-watchr-emacs.rb', line 192

def rspec_files *files
  rspec files.join(' ')
end

#rspec_send_results(results) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/rspec-rails-watchr-emacs.rb', line 159

def rspec_send_results(results)
  begin
    print "--- Sending notification to #{@enotify_host}:#{@enotify_port}" \
    " through #{@enotify_slot_id}... ".cyan
    esend_results results 
    puts "Success!".green
  rescue
    puts "Failed!".red
    init_network
    rspec_send_results results 
  end
end

#specs_for(path) ⇒ Object



196
197
198
199
200
201
# File 'lib/rspec-rails-watchr-emacs.rb', line 196

def specs_for(path)
  print "--- Searching specs for #{path.inspect}...".yellow
  specs = match_specs path, Dir['spec/**/*_spec.rb']
  puts specs.empty? ? ' nothing found.'.red : " #{specs.size} matched.".green
  specs
end