I have this error when I tried to implement "Fakeweb" and I do not understand the problem.
Scenario: "After user had filled in all the information, the system will use one of the attributes "fbid" for validation and if success then only a new company will be created, if not the process will fail."
Failures:
1) Companies new company create with valid information correct facebook id validates facebook id
Failure/Error: it "should create a company" do
NoMethodError:
undefined method `it' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_3::Nested_1::Nested_1:0x00000102fb84e0>
# ./spec/requests/companies_spec.rb:40:in `block (5 levels) in <top (required)>'
companies_spec.rb
describe "correct facebook id" do
#validate fbid
it "validates facebook id" do
FakeWeb.register_uri(:head, "http://graph.facebook.com/examplecompany", :username => 'examplecompany')
Company.new(:url => "http://graph.facebook.com/examplecompany").fb_id_string.should eq('examplecompany')
it "should create a company" do
expect { click_button submit }.to change(Company, :count).by(1)
end
model/company.rb
def fb_id_string
uri = URI.parse(url)
response = Net::HTTP.start(uri.host, uri.port) { |http| http.request_head(uri.path) }
response["username"].to_str
end
end
Since doing a Google search for
rspec nested itdoesn't yield anything, I thought I'd elaborate a little on @apneadiving's comment.While rspec allows
describeand its synonyms to be nested arbitrarily and whileitis similar todescribein its structure when passed a string argument, anitblock can only contain mocks, expectations, application code and vanilla Ruby. It cannot contain other invocations ofitor, for that matter,before,afterorlet. It can invokesubject, but doing so just invokes the block that subject was defined as; it will not redefine subject.Conversely, mocks and expectations cannot be expressed directly within
describe. They must be contained withinit.