Skip to content

Commit ab1f5b6

Browse files
Updated README files to add code blocks around example Ruby code. Updated Feature files to identify type of code within code blocks.
1 parent bce9bd1 commit ab1f5b6

File tree

11 files changed

+71
-10
lines changed

11 files changed

+71
-10
lines changed

features/Generators.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ out of the box for with Rails' defaults.
1010

1111
RSpec generators can also be run independently. For instance,
1212

13+
```shell
1314
rails generate rspec:model widget
15+
```
1416

1517
will create a new spec file in `spec/models/widget_spec.rb`.
1618

features/GettingStarted.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,62 @@
22

33
Install Rails 6
44

5+
```shell
56
$ gem install rails -v "~> 6.0.0"
7+
```
68

79
### Generate an app
810

11+
```shell
912
$ rails new example_app
1013
$ cd example_app
14+
```
1115

1216
### Add `rspec-rails` to the Gemfile
1317

18+
```shell
1419
$ echo 'gem "rspec-rails", group: [:development, :test]' >> Gemfile
20+
```
1521

1622
### Install the bundle
1723

24+
```shell
1825
$ bundle install
26+
```
1927

2028
### Bootstrap RSpec
2129

30+
```shell
2231
$ rails generate rspec:install
32+
```
2333

2434
### Generate a scaffold
2535

36+
```shell
2637
$ rails generate scaffold Widget name:string
38+
```
2739

2840
This generates files in the `app` and `spec` directories. The files in the
2941
`app` directory are generated by Rails, and Rails delegates the generation of
3042
the files in the `spec` directory to RSpec.
3143

3244
### Run migrations
3345

46+
```shell
3447
$ rails db:migrate && rails db:test:prepare
48+
```
3549

3650
### Run RSpec
3751

52+
```shell
3853
$ rake spec
54+
```
3955

4056
or
4157

58+
```shell
4259
$ rspec spec --format documentation
60+
```
4361

4462
If all went well, you should see output ending with:
4563

features/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ for even older versions.
1515

1616
## Install
1717

18+
```shell
1819
gem install rspec-rails
20+
```
1921

2022
This installs the following gems:
2123

@@ -29,23 +31,29 @@ This installs the following gems:
2931

3032
Add rspec-rails to the :test and :development groups in the Gemfile:
3133

34+
```ruby
3235
group :test, :development do
3336
gem 'rspec-rails', '~> 6.0.0'
3437
end
38+
```
3539

3640
It needs to be in the :development group to expose generators and rake tasks
3741
without having to type RAILS_ENV=test.
3842

3943
Now you can run:
4044

45+
```shell
4146
bundle exec rails generate rspec:install
47+
```
4248

4349
This adds the spec directory and some skeleton files, including a .rspec
4450
file.
4551

4652
You can also customize the default spec path with `--default-path` option:
4753

54+
```shell
4855
bundle exec rails generate rspec:install --default-path behaviour
56+
```
4957

5058
## Issues
5159

features/Transactions.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
When you run `rails generate rspec:install`, the `spec/rails_helper.rb` file
44
includes the following configuration:
55

6+
```ruby
67
RSpec.configure do |config|
78
config.use_transactional_fixtures = true
89
end
10+
```
911

1012
The name of this setting is a bit misleading. What it really means in Rails
1113
is "run every test method within a transaction." In the context of rspec-rails,
@@ -21,9 +23,11 @@ If you prefer to manage the data yourself, or using another tool like
2123
[database_cleaner](https://github.com/bmabey/database_cleaner) to do it for you,
2224
simply tell RSpec to tell Rails not to manage transactions:
2325

26+
```ruby
2427
RSpec.configure do |config|
2528
config.use_transactional_fixtures = false
2629
end
30+
```
2731

2832
### Data created in `before(:example)` are rolled back
2933

@@ -32,6 +36,7 @@ the example. This is a good thing because it means that each example is
3236
isolated from state that would otherwise be left around by the examples that
3337
already ran. For example:
3438

39+
```ruby
3540
describe Widget do
3641
before(:example) do
3742
@widget = Widget.create
@@ -45,6 +50,7 @@ already ran. For example:
4550
expect(@widget).to do_something_else
4651
end
4752
end
53+
```
4854

4955
The `@widget` is recreated in each of the two examples above, so each example
5056
has a different object, _and_ the underlying data is rolled back so the data
@@ -60,27 +66,31 @@ guidelines:
6066

6167
1. Be sure to clean up any data in an `after(:context)` hook:
6268

69+
```ruby
6370
before(:context) do
6471
@widget = Widget.create!
6572
end
6673

6774
after(:context) do
6875
@widget.destroy
6976
end
77+
```
7078

71-
If you don't do that, you'll leave data lying around that will eventually
72-
interfere with other examples.
79+
If you don't do that, you'll leave data lying around that will eventually
80+
interfere with other examples.
7381

7482
2. Reload the object in a `before(:example)` hook.
7583

84+
```ruby
7685
before(:context) do
7786
@widget = Widget.create!
7887
end
7988

8089
before(:example) do
8190
@widget.reload
8291
end
92+
```
8393

84-
Even though database updates in each example will be rolled back, the
85-
object won't _know_ about those rollbacks so the object and its backing
86-
data can easily get out of sync.
94+
Even though database updates in each example will be rolled back, the
95+
object won't _know_ about those rollbacks so the object and its backing
96+
data can easily get out of sync.

features/controller_specs/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ To specify outcomes, you can use:
4242

4343
## Examples
4444

45+
```ruby
4546
RSpec.describe TeamsController do
4647
describe "GET index" do
4748
it "assigns @teams" do
@@ -56,6 +57,7 @@ To specify outcomes, you can use:
5657
end
5758
end
5859
end
60+
```
5961

6062
## Views
6163

@@ -67,6 +69,7 @@ To specify outcomes, you can use:
6769

6870
We encourage you to use [request specs](./request-specs/request-spec) if you want to set headers in your call. If you still want to use controller specs with custom http headers you can use `request.headers`:
6971

72+
```ruby
7073
require "rails_helper"
7174
7275
RSpec.describe TeamsController, type: :controller do
@@ -78,3 +81,4 @@ We encourage you to use [request specs](./request-specs/request-spec) if you wan
7881
end
7982
end
8083
end
84+
```

features/mailer_specs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ behavior and expectations.
99

1010
## Examples
1111

12+
```ruby
1213
require "rails_helper"
1314

1415
RSpec.describe Notifications, type: :mailer do
@@ -26,3 +27,4 @@ behavior and expectations.
2627
end
2728
end
2829
end
30+
```

features/matchers/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ rspec-compatible wrappers for Rails' assertions.
55

66
### redirects
77

8+
```ruby
89
# delegates to assert_redirected_to
910
expect(response).to redirect_to(path)
11+
```
1012

1113
### templates
1214

15+
```ruby
1316
# delegates to assert_template
1417
expect(response).to render_template(template_name)
18+
```
1519

1620
### assigned objects
1721

22+
```ruby
1823
# passes if assigns(:widget) is an instance of Widget
1924
# and it is not persisted
2025
expect(assigns(:widget)).to be_a_new(Widget)
26+
```

features/model_specs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ behavior and expectations.
99

1010
## Examples
1111

12+
```ruby
1213
require "rails_helper"
1314

1415
RSpec.describe Post, type: :model do
@@ -21,3 +22,4 @@ behavior and expectations.
2122
end
2223
end
2324
end
25+
```

features/request_specs/request_spec.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ Feature: Request specs
1717

1818
RSpec provides two matchers that delegate to Rails assertions:
1919

20+
```ruby
2021
render_template # delegates to assert_template
2122
redirect_to # delegates to assert_redirected_to
23+
```
2224

2325
Check the Rails docs for details on these methods as well.
2426

features/routing_specs/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@ Simple apps with nothing but standard RESTful routes won't get much value from
77
routing specs, but they can provide significant value when used to specify
88
customized routes, like vanity links, slugs, etc.
99

10+
```ruby
1011
expect(:get => "/articles/2012/11/when-to-use-routing-specs").to route_to(
1112
:controller => "articles",
1213
:month => "2012-11",
1314
:slug => "when-to-use-routing-specs"
1415
)
16+
```
1517

1618
They are also valuable for routes that should not be available:
1719

20+
```ruby
1821
expect(:delete => "/accounts/37").not_to be_routable
22+
```

0 commit comments

Comments
 (0)