Skip to content
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

rename adapters "profiles" #207

Merged
merged 1 commit into from
Feb 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Unreleased ([changes](https://github.com/colszowka/simplecov/compare/v0.7.0...ma
-------------------

* [FEATURE] Adds support for Rails 4 command guessing.
* Rename adapters to "profiles" given that they are bundles of settings

v0.7.1, 2012-10-12 ([changes](https://github.com/colszowka/simplecov/compare/v0.7.0...v0.7.1))
-------------------
Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ end

coverage

If you're making a Rails application, SimpleCov comes with a built-in adapter (see below for more information on what adapters are)
If you're making a Rails application, SimpleCov comes with a built-in configurations (see below for information on profiles)
which will get you started with groups for your Controllers, Views, Models and Helpers. To use it, the first two lines of
your test_helper should be like this:

Expand Down Expand Up @@ -388,17 +388,17 @@ COVERAGE=true rake test
```


## Adapters
## Profiles

By default, Simplecov's only config assumption is that you only want coverage reports for files inside your project
root. To save you from repetitive configuration, you can use predefined blocks of configuration, called 'adapters',
root. To save you from repetitive configuration, you can use predefined blocks of configuration, called 'profiles',
or define your own.

You can then pass the name of the adapter to be used as the first argument to SimpleCov.start. For example, simplecov
comes bundled with a 'rails' adapter. It looks somewhat like this:
You can then pass the name of the profile to be used as the first argument to SimpleCov.start. For example, simplecov
comes bundled with a 'rails' profile. It looks somewhat like this:

```ruby
SimpleCov.adapters.define 'rails' do
SimpleCov.profiles.define 'rails' do
add_filter '/test/'
add_filter '/config/'

Expand All @@ -410,7 +410,7 @@ SimpleCov.adapters.define 'rails' do
end
```

As you can see, it's just a glorified SimpleCov.configure block. In your test_helper.rb, launch simplecov with:
As you can see, it's just a SimpleCov.configure block. In your test_helper.rb, launch simplecov with:

```ruby
SimpleCov.start 'rails'
Expand All @@ -424,26 +424,26 @@ SimpleCov.start 'rails' do
end
```

### Custom adapters
### Custom profiles

You can load additional adapters with the SimpleCov.load_adapter('xyz') method. This allows you to build upon an existing
adapter and customize it so you can reuse it in unit tests and cucumber features, for example.
You can load additional profiles with the SimpleCov.load_profile('xyz') method. This allows you to build upon an existing
profile and customize it so you can reuse it in unit tests and cucumber features, for example.

```ruby
# lib/simplecov_custom_adapter.rb
# lib/simplecov_custom_profile.rb
require 'simplecov'
SimpleCov.adapters.define 'myadapter' do
load_adapter 'rails'
SimpleCov.profiles.define 'myprofile' do
load_profile 'rails'
add_filter 'vendor' # Don't include vendored stuff
end

# features/support/env.rb
require 'simplecov_custom_adapter'
SimpleCov.start 'myadapter'
require 'simplecov_custom_profile'
SimpleCov.start 'myprofile'

# test/test_helper.rb
require 'simplecov_custom_adapter'
SimpleCov.start 'myadapter'
require 'simplecov_custom_profile'
SimpleCov.start 'myprofile'
```


Expand Down
44 changes: 0 additions & 44 deletions features/config_adapters.feature

This file was deleted.

44 changes: 44 additions & 0 deletions features/config_profiles.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@test_unit @config @profiles
Feature:

In order to re-use SimpleCov settings across projects,
profiles can be defined that hold configuration settings
that can be loaded at once.

Background:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
"""

Scenario: Defining and using a custom profile
Given a file named ".simplecov" with:
"""
SimpleCov.profiles.define 'custom_command' do
command_name "Profile Command"
end

SimpleCov.start do
load_profile 'test_frameworks'
load_profile 'custom_command'
end
"""

When I open the coverage report generated with `bundle exec rake test`
Then I should see "4 files in total."
And I should see "using Profile Command" within "#footer"

Scenario: Using existing profile in custom profile and supplying profile to start command
Given a file named ".simplecov" with:
"""
SimpleCov.profiles.define 'my_profile' do
load_profile 'test_frameworks'
command_name "My Profile"
end

SimpleCov.start 'my_profile'
"""

When I open the coverage report generated with `bundle exec rake test`
Then I should see "4 files in total."
And I should see "using My Profile" within "#footer"
19 changes: 12 additions & 7 deletions lib/simplecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class << self

#
# Sets up SimpleCov to run against your project.
# You can optionally specify an adapter to use as well as configuration with a block:
# You can optionally specify a profile to use as well as configuration with a block:
# SimpleCov.start
# OR
# SimpleCov.start 'rails' # using rails adapter
# SimpleCov.start 'rails' # using rails profile
# OR
# SimpleCov.start do
# add_filter 'test'
Expand All @@ -22,9 +22,9 @@ class << self
#
# Please check out the RDoc for SimpleCov::Configuration to find about available config options
#
def start(adapter=nil, &block)
def start(profile=nil, &block)
if SimpleCov.usable?
load_adapter(adapter) if adapter
load_profile(profile) if profile
configure(&block) if block_given?
@result = nil
self.running = true
Expand Down Expand Up @@ -89,10 +89,15 @@ def grouped(files)
end

#
# Applies the adapter of given name on SimpleCov configuration
# Applies the profile of given name on SimpleCov configuration
#
def load_profile(name)
profiles.load(name)
end

def load_adapter(name)
adapters.load(name)
warn "method load_adapter is deprecated. use load_profile instead"
load_profile(name)
end

#
Expand All @@ -118,7 +123,7 @@ def usable?
SimpleCov.send :extend, SimpleCov::Configuration
require 'simplecov/exit_codes'
require 'simplecov/json'
require 'simplecov/adapters'
require 'simplecov/profiles'
require 'simplecov/source_file'
require 'simplecov/file_list'
require 'simplecov/result'
Expand Down
9 changes: 7 additions & 2 deletions lib/simplecov/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,15 @@ def groups
end

#
# Returns the hash of available adapters
# Returns the hash of available profiles
#
def profiles
@profiles ||= SimpleCov::Profiles.new
end

def adapters
@adapters ||= SimpleCov::Adapters.new
warn "method adapters is deprecated. use profiles instead"
profiles
end

#
Expand Down
10 changes: 5 additions & 5 deletions lib/simplecov/defaults.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Load default formatter gem
require 'simplecov-html'

SimpleCov.adapters.define 'root_filter' do
SimpleCov.profiles.define 'root_filter' do
# Exclude all files outside of simplecov root
add_filter do |src|
!(src.filename =~ /^#{SimpleCov.root}/)
end
end

SimpleCov.adapters.define 'test_frameworks' do
SimpleCov.profiles.define 'test_frameworks' do
add_filter '/test/'
add_filter '/features/'
add_filter '/spec/'
add_filter '/autotest/'
end

SimpleCov.adapters.define 'rails' do
load_adapter 'test_frameworks'
SimpleCov.profiles.define 'rails' do
load_profile 'test_frameworks'

add_filter '/config/'
add_filter '/db/'
Expand All @@ -34,7 +34,7 @@
SimpleCov.configure do
formatter SimpleCov::Formatter::HTMLFormatter
# Exclude files outside of SimpleCov.root
load_adapter 'root_filter'
load_profile 'root_filter'
end

# Gotta stash this a-s-a-p, see the CommandGuesser class and i.e. #110 for further info
Expand Down
16 changes: 8 additions & 8 deletions lib/simplecov/adapters.rb → lib/simplecov/profiles.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
#
# Adapters are glorified SimpleCov configuration procs that can be easily
# Profiles are SimpleCov configuration procs that can be easily
# loaded using SimpleCov.start :rails and defined using
# SimpleCov.adapters.define :foo do
# SimpleCov.profiles.define :foo do
# # SimpleCov configuration here, same as in SimpleCov.configure
# end
#
class SimpleCov::Adapters < Hash
class SimpleCov::Profiles < Hash
#
# Define a SimpleCov adapter:
# SimpleCov.adapters.define 'rails' do
# Define a SimpleCov profile:
# SimpleCov.profiles.define 'rails' do
# # Same as SimpleCov.configure do .. here
# end
#
def define(name, &blk)
name = name.to_sym
raise "SimpleCov Adapter '#{name}' is already defined" unless self[name].nil?
raise "SimpleCov Profile '#{name}' is already defined" unless self[name].nil?
self[name] = blk
end

#
# Applies the adapter of given name on SimpleCov.configure
# Applies the profile of given name on SimpleCov.configure
#
def load(name)
name = name.to_sym
raise "Could not find SimpleCov Adapter called '#{name}'" unless has_key?(name)
raise "Could not find SimpleCov Profile called '#{name}'" unless has_key?(name)
SimpleCov.configure(&self[name])
end
end
6 changes: 3 additions & 3 deletions test/test_1_8_fallbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class Test18FallBacks < Test::Unit::TestCase
assert_equal false, SimpleCov.configure { raise "Shouldn't reach this!?" }
end

should "allow to define an adapter" do
should "allow to define a profile" do
begin
SimpleCov.adapters.define 'testadapter' do
SimpleCov.profiles.define 'testprofile' do
add_filter '/config/'
end
rescue => err
assert false, "Adapter definition should have been fine, but raised #{err}"
assert false, "Profile definition should have been fine, but raised #{err}"
end
end
end if RUBY_VERSION.start_with? '1.8'