Define a custom matcher for this. Here is a first draft of this. Could need some finetuning.

```ruby
Spec::Matchers.define :accept_css_name do |css_name|
  match do |layer|
    layer.update_attributes name: name
    layer.error_on(:name) == 0
  end
end

it 'does not accept names with whitespace' do
  expect(layer).to_not accept_css_name 'this is an invalid css class'
end

it 'accepts a valid css name' do
  expect(layer).to accept_css_name 'this-is_a_valid_css-class-12345'
end
```


Your matcher can also optionally define these methods if that makes errors easier to read.

```ruby
failure_message_for_should do |player|
  # generate and return the appropriate string.
end
failure_message_for_should_not do |player|
  # generate and return the appropriate string.
end
```